Discussion:
[Larceny-users] Probably not a bug in R6RS, but...
David Rush
2008-12-15 10:57:38 UTC
Permalink
So I've been using larceny as an over-amplified desk calculator while
doing some statistical program analyses and I got a little tired of
typing out LAMBDA all the time, so...
(define-syntax \ (syntax-rules () ((\ v e0 e+ ...) (lambda v e0 e+ ...))))
\x20;
(\ (a b) (+ a b))
#<PROCEDURE>
((\ (a b) (+ a b)) 2 3)
Error: Undefined global variable "b".
Entering debugger; type "?" for help.
debug> q
(define-syntax \\ (syntax-rules () ((\\ v e0 e+ ...) (lambda v e0 e+ ...))))
\x5c;
((\\ (a b) (+ a b)) 2 3)
5

Which I guess is technically correct, but is rather surprising
nonetheless. Specifically, it is surprising that the REPL created a
procedure using the LAMBDA == \ substitution, but then it was unable
to apply it; whereas when using LAMBDA == L, everything worked just
fine.

And yes, I didn't *really* mean to make #\space into a symbol that was
equivalent to LAMBDA in the first place, but I still think that this
half-functional situation is odd. It looks like maybe there is some
interference with the lexer...

Should I report this as a bug?

david rush
--
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
Felix Klock
2008-12-15 15:22:42 UTC
Permalink
David (cc'ing larceny-users)-
Post by David Rush
And yes, I didn't *really* mean to make #\space into a symbol that was
equivalent to LAMBDA in the first place, but I still think that this
half-functional situation is odd. It looks like maybe there is some
interference with the lexer...
Yes, I concur that this is likely to be a lexing/parsing issue.

% ~/bin/larceny
Larceny v0.964+ "Fluoridation" (Aug 12 2008 22:00:42, precise:Posix
Unix:unified)
larceny.heap, built on Tue Aug 12 22:01:04 EDT 2008
Post by David Rush
(define-syntax \ (syntax-rules () ((\ v e0 e+ ...) (lambda v e0 e
+ ...))))
\x20;
Post by David Rush
(macro-expand '(\ v (apply + v)))
((lambda () (\x20;v (apply + v))))
Post by David Rush
(macro-expand '(\ v (apply + v)))
((lambda ()
(lambda \x2e;v\x7c;1\x7c;2 (begin v (apply + v)))))

Funny stuff.

Oh, actually, I think I just figured out your problem: the macro
pattern (\ v e0 e+ ...) is treating the entirety of '\ v' as a single
token.

So if you like, you can try this instead:

% ~/bin/larceny
Larceny v0.964+ "Fluoridation" (Aug 12 2008 22:00:42, precise:Posix
Unix:unified)
larceny.heap, built on Tue Aug 12 22:01:04 EDT 2008
Post by David Rush
(define-syntax \ (syntax-rules () ((\ v e0 e+ ...) (lambda v e0 e
+ ...))))
\x20;
Post by David Rush
(\ (a b) (+ a b))
#<PROCEDURE>
Post by David Rush
((\ (a b) (+ a b)) 1 2)
3


Note that in the latter, I am carefully placing at least two spaces
after the '\' character.

(As for your question of whether it should be filed as a bug -- I
figure the worst that can happen is that we'll assign in a status like
"wontfix" or "notabug". I do ask though that if you do file it as a
bug, make sure to describe what the expected behavior should be -- the
only reason I have not filed a bug on this myself is that it is not
immediately obvious what behavior one should expect here -- the
current behavior may be entirely correct, and the problem is that your
macro was incorrectly written, as I describe above.)

-Felix
William D Clinger
2008-12-15 17:58:45 UTC
Permalink
Post by David Rush
Should I report this as a bug?
I don't think you need to file a bug ticket. The use
of \ as an escape character within symbols is not a
legal R5RS, ERR5RS, or R6RS syntax, and is already
deprecated (see the read-traditional-weirdness?
parameter [1]). If this is considered to be a bug,
the most likely way we'd fix it is to drop support
for that weirdness or to change the defaults so you
couldn't use any of the traditional weirdness without
some kind of #!traditional-weirdness flag.

In any event, the \ escape appears to be working as
documented, so the only bug here would be with its
traditional semantics or with our decision to support
that semantics.

You could use the Greek letter lambda instead of a
backslash, and I think that's likely to become a
common convention as more implementations support
Unicode. In Larceny v0.97b1, however, that works
only for interactive ports and only when the -utf8
option was specified on the command line. (It's
possible to use UTF-8 or UTF-16 in source code files,
but doing so is too awkward and undocumented for
non-wizards.) For now, you can use \x3bb; in source
files and the Greek letter lambda at the REPL.

Depending on your machine, of course, it may be more
trouble to type a real Greek lambda than to type the
traditional "lambda" or the R6RS "\x3bb;". Oh well.

Will


[1] https://trac.ccs.neu.edu/trac/larceny/wiki/LexicalConversion

Continue reading on narkive:
Loading...