[Larceny-users] Larceny basics
Felix
felixluser at pnkfx.org
Sat Sep 1 11:37:04 EDT 2007
Dan-
On Aug 31, 2007, at 7:38 PM, Dan Muresan wrote:
> I must be missing something; are there any other simple examples
> that highlight the issue? I looked at the Trac page about extending
> (require), but without an example I'm not sure exactly what you're
> trying to say.
Okay, I think I have a more illustrative example.
SRFI-8 defines a receive macro to ease programming with multiple values.
Here is its definition (cut-and-pasted from Larceny's srfi-8 code).
(define-syntax receive
(syntax-rules ()
((receive formals expression body ...)
(call-with-values (lambda () expression)
(lambda formals body ...)))))
Observe the behavior given in the interactions below.
% cat test.sch
(require 'srfi-8)
(define (successor x) (values x (+ x 1)))
(receive (y z) (successor 3)
(display (list y z))
(newline))
% /usr/local/bin/larceny
Larceny v0.93 "Deviated Prevert" (Nov 10 2006 04:27:45, precise:BSD
Unix:unified)
> (load "test.sch") ;; works as expected
(3 4)
> (exit)
% /usr/local/bin/larceny
Larceny v0.93 "Deviated Prevert" (Nov 10 2006 04:27:45, precise:BSD
Unix:unified)
> (compile-file "test.sch" "compiled1.fasl") ;; oops wrong syntax env
> (load "compiled1.fasl")
Error: environment-get-cell: denotes a macro: receive
Entering debugger; type "?" for help.
debug> a
% /usr/local/bin/larceny
Larceny v0.93 "Deviated Prevert" (Nov 10 2006 04:27:45, precise:BSD
Unix:unified)
> (require 'srfi-8)
#t
> (compile-file "test.sch" "compiled2.fasl") ;; syntax env is
appropriate this time
> (load "compiled2.fasl")
(3 4)
> (exit)
%
Note that test.sch explicitly expresses, via require, that it depends
on SRFI-8, but in Larceny, the require procedure is a runtime
construct rather than a special form handled during expansion of
test.sch. Therefore the compiler is not aware that the subsequent
code depends on the receive special form from SRFI-8 when expanding
the remaining expressions in the file. The (receive ...) expression
is compiled into a procedure invocation with a reference to the
global variable named "receive", and we get an error when we load the
file because the variable reference cannot be linked to the macro
denoted by "receive."
These sorts of problems are no surprise to people who have been
programming Scheme solely using constructs like the load procedure
while also attempting to compile their files. But since require-
extension is a special form, one might think that it should be smart
enough to inform the compiler about such dependencies. See for
example how PLT Scheme handles importing macros in its module system
[1].
This is the detail I was trying to point out about potential
alternative implementations of SRFI-55. I do not know how the
implementation of require-extension works in other Schemes (e.g.
Chicken), and it is not clear to me from the SRFI-55 specification
how requiire-extension is supposed to interact with compilation, so I
thought it best to warn you ahead of time that my simple syntax-rules
macro for require-extension might not suffice for your purposes.
-Felix
[1] http://www.cs.utah.edu/plt/publications/macromod.pdf
More information about the Larceny-users
mailing list