On Wed, Oct 28, 2009 at 12:21 AM, Alex Osborne <a...@meshy.org> wrote:
>
> Jeff Brown wrote:
>
>> I can invoke a function using Java code that looks something like this...
>>
>> Reader reader = new FileReader("clj/demo.clj");
>> Compiler.load(reader);
>> Var var = RT.var("demo", "add_numbers");
>> Object result = var.invoke(4, 7);
>> System.out.println("Result: " + result);
>>
>> I am not sure how to invoke even_sillier_adder.  Any help would be
>> appreciated.
>>
>
> Maybe I'm missing the point of the question, but can't you just do it
> exactly the same way?
>
>   Reader reader = new FileReader("clj/demo.clj");
>   Compiler.load(reader);
>   Var var = RT.var("demo", "even_sillier_adder");
>
>   Object result = var.invoke(4);
>   System.out.println("Result: " + result);
>   System.out.println("Result evaluated: " + Compiler.eval(result));
>
> Output:
>
>   Result: (foo/silly_adder 9)
>   Result evaluated: 9
>
> A macro is just a function that takes some code and returns some other
> code, so "invoking" a macro will return the code it evaluates to.  If
> you want that to be then evaluated, then just ask the compiler to
> evaluate it. ;-)
>

It is best not to rely on the fact that macros are implemented as
functions. They are like functions, and may be actual functions now,
but that is an implementation detail.

The way to do macroexpansion is via macroexpand and macroexpand-1,
both of which can be called from Java via binding RT.vars as above. If
you then want to evaluate the expansion, use eval.

Rich

--~--~---------~--~----~------------~-------~--~----~
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