Open phlummox opened 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:
(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
):
Added an import of (scheme)
from SRFI 1 to prevent this compilation error.
Many thanks!
No problem, sorry for the trouble.
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) andmake-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 likereceive
don't need to be imported. e.g. the following works fine in the repl:huskc
.(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):It seems that although the suggested method of importing 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 ofrequire
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, perhapsrequire
and other definitions could be included inlib/scheme/base.sld
, or one of the other standard libraries. I can provide a patch forrequire
, but haven't checked to see exactly what other definitions might need including.