This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Problems with square brackets
On Aug 31, 2011, at 8:02 PM, John-Paul Verkamp wrote:
In 'CHANGES FROM KAWA 1.6.56 TO 1.6.58' it's mentioned that 'Square
brackets [ ... ] are allowed as a synonym of parentheses ( ... ).'.
But when I try Kawa (either using eval(...) or using the Kawa REPL
directly, I get this:
#|kawa:1|# (let ([x 5]) x)
/dev/stdin:2:1: let binding is not a pair:[x
The same thing happens for cond, etc.
Is there a way to enable this?
I'm particularly interested in it working correctly when using (load
"..."). When I'm using eval(...) I can just do a quick replace to work
around the issue.
Thanks!
A while back, (after the release of 1.11, I think), Per changed the
default
bracket behavior to facilitate the construction of immutable literal
vectors
or (Java) arrays. You can change this by calling
ReadTable#setBracketMode(),
which says:
/** Specify how '[' and ']' (and '<') are handled.
* The value -2 means {@code [a b c]} is {@code ($bracket-list$ a b
c)}
* and {@code f[a b]} is {@code ($bracket-apply$ f a b)}.
* The value -1 means that '[' and ']' are plain token constituents.
* The value 0 means that '[' and ']' are equivalent to '(' and ')'.
* The value 1 means that '[' and ']' are equivalent to '(' and
')', except
* within a token starting with '<', in which case they are
constituents.
* This is so '[' is non-terminating when reading say '<char[]>'
*/
The default value is currently -2. If you change it to 1, then Racket-
style
brackets==parens will work (though I think Racket limits the meaning of
brackets to certain contexts, like within a let; this will make them
equivalent everywhere):
#|kawa:1|# [display "hello"]
#(#<procedure display> hello)
#|kawa:2|# (set! (gnu.kawa.lispexpr.ReadTable:get-current):bracket-
mode 1)
#|kawa:3|# [display "hello"]
hello
#|kawa:4|# (let ([a 3] [b 4]) (sqrt (+ (* a a) (* b b))))
5.0
I think if you limit yourself to more-or-less portable Scheme code, you
should be fine with that, it'll just cost you some brevity if you do
Kawa-specific coding where $bracket-list$ is a handy shortcut.
For instance, instead of being able to write
(define my-array-of-doubles ::double[] [1 2 3 4 5])
you'll have to write
(define my-array-of-doubles ::double[] (double[] 1 2 3 4 5)).
Per, setting the bracket mode seems like a plausible candidate for a
"#!"
special form a la #!fold-case.
-Jamie
--
Jamison Hope
The PTR Group
www.theptrgroup.com