This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: (eval '(java.lang.System:nanoTime)) won't work
- From: Per Bothner <per at bothner dot com>
- To: Morven Sun <sunixm at gmail dot com>
- Cc: kawa at sourceware dot org
- Date: Sun, 09 Jun 2013 13:14:00 -0700
- Subject: Re: (eval '(java.lang.System:nanoTime)) won't work
- References: <CAKZUWfh6SexU3=Y8sch_BAfERoA4Agn8pOmDZTep9cynmgzmUA at mail dot gmail dot com> <51B42DD2 dot 7050406 at bothner dot com> <CAKZUWfjJfouMHPZvTdRX5K1W8OTF_2gSQO6nERQLzazhGF40pw at mail dot gmail dot com>
On 06/09/2013 01:38 AM, Morven Sun wrote:
I now know the reason. With the problem like this the Kawa language
itself seems a little inconsistent.
Scheme is pure though procedureless. :) with great uniform syntax and meanings.
Generic Scheme has a number of inconsistencies and awkward issues.
The colon notation is a good extension for bringing lots of
functionality to scheme.
But the problem with eval and quoted form, I think Kawa break the
basic compatibility with Scheme.
Right - the colon notation does that. However, we want to make
it easy to "port" Scheme programs to Kawa. Plus we want to make
it easy for people who are looking for "Scheme" (rather than "Kawa"),
but need/want to run on the Java platform.
Here I want to define a macro to display every thing to output, I do
it like this:
(define-syntax println
(syntax-rules ()
((println x ...)
(map display '(x ...)))))
With this macro I can do primitive print like:
(println 1 2 3) => 1 2 3
But when come into :
(println 1 2 (+ 2 3 4)) => 1 2 (+ 2 3 4)
If i want to make (+ 2 3 4) evaluated, I can redefine the macro:
(define-syntax println
(syntax-rules ()
((println x ...)
(map (lambda (y) (display (eval y))) '(x ...)))))
It's ok with normal scheme variables, but when the colon notation
comes into view, things're just broken.
It's frustrated.
In most cases, if you're using eval, you're doing something wrong.
Eval breaks name scoping and many of the desirable properties
of Scheme (the evaluated code can't see the lexical context
it's nested in). Plus of course it's a major performance-killer.
Perhaps the macro I defined is not quite correct. So what's the much
s> marter macro would be like?
Jamison gave the best suggestion. If you want to use a macro, you
can do:
(define-syntax println
(syntax-rules ()
((println x ...)
(begin (display x) ...))))
(println 1 2 (+ 2 3 4)) ==> 1 2 9
--
--Per Bothner
per@bothner.com http://per.bothner.com/