Re: Macros in interaction with Functions

2009-01-17 Thread Daniel Jomphe
Stuart Sierra wrote: > > - The reader performs a few substitutions, then gives the resulting > > code to the compiler. > > - The compiler starts by expanding macros into their substitution. > > --- Thus, for functions, there's no such thing as macros. > > --- Thus, all that functions see of mac

Re: Macros in interaction with Functions

2009-01-17 Thread Stuart Sierra
Hi Daniel, On Jan 16, 6:54 pm, Daniel Jomphe wrote: > I'll tell you my current understanding of how Clojure works, so you > can correct me where I may be wrong: > > - The compiler has for target a living environment; thus, it's > dynamic. > - There's no interpreter; thus, the following points wi

Re: Macros in interaction with Functions

2009-01-16 Thread Daniel Jomphe
Stuart Sierra said: > It's not covered much. You get used to it. Think of it this way -- macros > only exist during compilation. Functions like "apply" get evaluated at > run-time. A macro like "and" has no value at run-time, so you can't use it > as an argument to a function. I'll tell y

Re: Macros in interaction with Functions

2009-01-16 Thread Chouser
On Fri, Jan 16, 2009 at 3:41 PM, Michael Reid wrote: > >> Is there anyway to write a macro/function that acts as a function when >> necessary (so it can be passed as an argument), but expands into a >> macro (for speed) when deemed possible? > > I don't think this is possible without some sort of

Re: Macros in interaction with Functions

2009-01-16 Thread Michael Reid
> Is there anyway to write a macro/function that acts as a function when > necessary (so it can be passed as an argument), but expands into a > macro (for speed) when deemed possible? I don't think this is possible without some sort of support for a macro/function duality in core Clojure. In the

Re: Macros in interaction with Functions

2009-01-16 Thread Mark Volkmann
On Fri, Jan 16, 2009 at 12:49 PM, CuppoJava wrote: > > I'm also very interested in this topic. > > The only reason to write "and" as a macro is for performance reasons. That's not the only reason. Another reason is to have the option to avoid evaluating all of the arguments. Functions always eva

Re: Macros in interaction with Functions

2009-01-16 Thread Kevin Downey
and is also written as a macro to short circuit evaluation: clojure.core/and ([] [x] [x & rest]) Macro Evaluates exprs one at a time, from left to right. If a form returns logical false (nil or false), and returns that value and doesn't evaluate any of the other expressions, otherwise it re

Re: Macros in interaction with Functions

2009-01-16 Thread CuppoJava
I'm also very interested in this topic. The only reason to write "and" as a macro is for performance reasons. It's much more convenient, programming-wise, if and is a function. Is there anyway to write a macro/function that acts as a function when necessary (so it can be passed as an argument),

Re: Macros in interaction with Functions

2009-01-16 Thread Stuart Halloway
I second the vote for _On Lisp_. I have ported the examples to Clojure: http://blog.thinkrelevance.com/2008/12/12/on-lisp-clojure Stuart >> When I found that out, I was surprised. My knowledge of lisp comes >> from reading, in the past few months: >> - ANSI Common Lisp >> - Practical Common Lis

Re: Macros in interaction with Functions

2009-01-15 Thread Konrad Hinsen
On 16.01.2009, at 00:04, Daniel Jomphe wrote: > When I found that out, I was surprised. My knowledge of lisp comes > from reading, in the past few months: > - ANSI Common Lisp > - Practical Common Lisp > and, some years ago, a few more things. The best book to read about macros is in my opinion

Re: Macros in interaction with Functions

2009-01-15 Thread Timothy Pratley
> fuzzy in my mind how some functions interact well with macros while > some others don't. Good: (some-function (some-macro stuff)) Bad: (some-function some-macro stuff) For me I find it easiest to remember as "macros are not first class functions" ie: they cannot be passed to and executed by o

Re: Macros in interaction with Functions

2009-01-15 Thread Stuart Sierra
On Jan 15, 6:04 pm, Daniel Jomphe wrote: > And still, I wasn't prepared for the fact that macros don't mix 100% > with functions. Either I overlooked an important section in these > books, or they didn't really cover it much. It's not covered much. You get used to it. Think of it this way -- m