A broader analysis of this: because macros work at compile-time, not at runtime, you need to know the number of arguments in advance. That means

for the case of 'and', it seems like if one had other call-by-*
semantics available in the lisp, then one wouldn't have to use a
compile-time macro?

Depends on why you're using a macro.

Calling semantics don't matter in the case of a macro. The definition of "macro" is that it generates code prior to runtime. If you don't know the arguments to be provided (e.g., you're using apply), macroexpansion simply cannot occur. (You can delay macroexpansion until runtime, but we've got a word for that: eval.)

You can sometimes avoid the use of a macro by using alternative evaluation strategies, whether that's provided by odd calling semantics, by pervasive laziness (e.g., one can implement `if` in Haskell using a function), or by manual thunking (or the use of `delay`). If that's what you mean, then the answer is "yes".

For example:

If `and` were a variadic function (defined for illustration's sake, not efficiency):

(defn and* [& args]
  (if (empty? args)
    true
    (and (first args)
         (and* (rest args)))))

then it will evaluate all of its arguments, not short-circuit:

user=> (and* (do (println "One") false) (do (println "Two") true))
One
Two
false

Now, if we explicitly thunk our arguments, and define `and**` to un- thunk:

(defn and** [& args]
  (if (empty? args)
    true
    (and ((first args))    ; Changed.
         (and** (rest args)))))

we get similar short-circuiting behavior to the macro version:

user=> (and** #(do (println "One") false) #(do (println "Two") true))
One
false

Does that answer your question?

-R

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to