Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem importing definitions that are in (scheme) but not (scheme base) #211

Open
phlummox opened this issue Oct 16, 2016 · 4 comments
Open

Comments

@phlummox
Copy link

Hi, this might be more a problem with my understanding of the documentation, than with husk. tl;dr: a bunch of definitions are included in (scheme) but not (scheme base), and this causes problems when trying to use them in libraries, or trying to import (srfi 1).

So, the "getting started" page lists a bunch of SRFI libraries which are supported. Two (SRFI-1 and SRFI-2) are mentioned as "not being included by default", making it necessary to import them. My assumption was that the other libraries listed are included by default, and don't need to be imported, but this doesn't seem to be so. For instance, receive (from SRFI 8) and make-record-type (from SRFI 9) do sometimes need to be imported (from what I can tell). And this also seems to make SRFI 1 not always work.
    The following seems to be true:

  • When executed in the top-level repl, or using huski -i <scriptname>, features like receive don't need to be imported. e.g. the following works fine in the repl:

      huski> (receive (odds evens) (values '(1 3 5) '(2 4 6))
         (write `(odds ,odds evens ,evens)))
      (odds (1 3 5) evens (2 4 6))
    
  • Likewise, those features work fine when use in the main file of a program compiled with huskc.

  • However, they aren't available automatically from within library files; furthermore, (import (scheme base)) will not suffice to import them, since they aren't part of (scheme base); but nor are they part of any of the other standard libraries listed in the manual, so it was not at all clear to me how to import them.

  • I eventually discovered, by looking through the library definitions, that they are part of (scheme) but not (scheme base), so when writing a library, this means one has to write (for example):

    (define-library (example mylib)
      (export mylib odds-and-evens)
      (import (scheme))
      (begin
        (define (odds-and-evens)
          (receive (odds evens) (values '(1 3 5) '(2 4 6))
            (write `(odds ,odds evens ,evens))))))
    
  • It seems that although the suggested method of importing SRFI 1,

    (import (srfi 1))
    

    works in the repl, it won't work in a program compiled with huskc (and without patching the source, I can't see any way of making it work), because SRFI 1 makes use of require and doesn't have access to its definition.

Perhaps the manual could explain somewhere that there are definitions which are part of (scheme) but not (scheme base), and how to import them? And perhaps the manual should also clarify that (import (srfi 1)) will only work in the repl, not in compiled programs.
    Alternatively, perhaps require and other definitions could be included in lib/scheme/base.sld, or one of the other standard libraries. I can provide a patch for require, but haven't checked to see exactly what other definitions might need including.

@phlummox
Copy link
Author

phlummox commented Oct 16, 2016

Ah - on looking through the test code in the repo, perhaps the issue is simply my failing to understand that when compiling with huskc, (import (srf 1)) doesn't work for importing (srfi 1), but (require-extension (srfi 1)) does.
  Perhaps it might be useful to add an example, somewhere in the documentation, of how to use an extension with huskc?

On further investigation:

  • (require-extension (srfi 1)) is required to enable SRFI 1 in huskc, but in huski, (import (srfi 1)) will work as well. However, both of those fail from within a library file, but (import (scheme) (srfi 1)) works instead.
  • (require-extension (srfi 8)) fails with an "extension not found" error in both huski and huskc, but receive is automatically available to a "main" program file anyway. However, it's not visible from library files, unless one uses (import (scheme)).

It all seems rather complicated. I didn't realize at all, from reading the manual, that this was what was required in order to use extensions; but perhaps I'm just not very familiar with the Scheme way of doing things.
    At any rate, I've attached, for your information, a patch with some test code which tries to make use of SRFI 1 from within a library, and fails to compile using huskc (though it works with huski):

    srfi-1-test.txt

justinethier added a commit that referenced this issue Oct 17, 2016
@justinethier
Copy link
Owner

Added an import of (scheme) from SRFI 1 to prevent this compilation error.

@phlummox
Copy link
Author

Many thanks!

@justinethier
Copy link
Owner

No problem, sorry for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants