justinethier / husk-scheme

A full implementation of the Scheme programming language for the Haskell Platform.
http://justinethier.github.io/husk-scheme
MIT License
309 stars 28 forks source link

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

Open phlummox opened 8 years ago

phlummox commented 8 years ago

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:

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 commented 8 years ago

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:

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 commented 8 years ago

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

phlummox commented 8 years ago

Many thanks!

justinethier commented 8 years ago

No problem, sorry for the trouble.