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. ;-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---