This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: (eval '(java.lang.System:nanoTime)) won't work


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]