Re: re-using comma for read-time evaluation
Ralf Juengling <[email protected]> Mon, 20 Oct 2008 19:06:41 -0700 (PDT)
| Newsgroups | gmane.lisp.lush.devel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 20 Oct 2008, Yann LeCun wrote: > >> The macro-character @ allows evaluation of expressions >> at read-time and, afaik, is mostly used when globally >> defined constants occur in code to be compiled. > > Actually "@@" is used for read-time evaluation. a single "@" > is used to access constants, but it's evaluated at run time > (or at macro-expansion time in compiled code). Ah, you're right, the @-macro creates another macro. The @-character may be followed by any expression, though, not just by a symbol. Hm. But you seem to agree that @ outside an array literal (and in the ,@-variant of the comma operator) is mainly used to access constants. Why don't we modify the compiler so that, when it does not find a symbol in its symbol tables, it looks if the symbol is globally bound, and, perhaps, locked? If this is the case, the compiler would just substitute (eval sym) for sym and goes from there. Thus, we could do completely without a special character for this use case. > One problem is that this would preclude the use of > constants within backquote expressions. Are you sure? I think ,, would do the trick. > Another question is: what do you want to use @ for? I did a little programming in Haskell a while ago and there are a lot of cool features in that language. One feature I like a lot, and which helps in writing succinct code, is partial evaluation. You could define the Lush function "1+" by simply writing plus1 = (+) 1 that is, you define a new function by fixing some arguments of an existing function. And because this is so succint (compare it to a lambda expression), you often don't explicitly define new functions that way but just write the expression on the spot. I would like to simulate partial evaluation and do something slightly more general with @ as the macro character. It would take the S-expression following @ and build a lambda expression from it. The symbols $1, $2, etc. and ... are treated special and would be used as explicit arguments in the lambda expression, the i in $i indicating the position. Here ares some examples of what I have in mind: @(+ 1 ...) -> (lambda ... (+ 1 . ...)) @(is-of-class $1 |HTABLE|) -> (lambda ($1) (is-of-class $1 |HTABLE|)) @(= (mod $1 2) 1) -> (lambda ($1) (= (mod $1 2) 1)) @(concat $2 $1 ...) -> (lambda ($1 $2 ...) (concat $2 $1 . ...)) It is basically a quite readable shortcut for defining lambda expressions. I think I would use lambdas much more often if they were so short and easy to write. Ralf ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/