Dynamically Reify Interfaces

121 views
Skip to first unread message

Nick Mudge

unread,
Nov 8, 2017, 1:43:00 AM11/8/17
to Clojure
I need to dynamically reify some java interfaces based on data from a map.  One way I can see to do this is to generate the reify code with a function using syntax quotes, quotes and unquote and unquote splice.  And then evaluate it using eval. I hesitate using eval, but is eval the right tool for this case?  

Normally I would write a macro to generate code. A macro is good for generating code from source code. But in this case the data that is used to generate the code is coming from a var that holds a data structure.

Any thoughts about when it is okay/good to use eval in Clojure?



Timothy Baldridge

unread,
Nov 8, 2017, 10:33:11 AM11/8/17
to clo...@googlegroups.com
Eval gets a bad reputation from languages like JS where it's messy and a bit of a security risk. In Clojure, there's nothing wrong with using eval for something like this. 

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
“One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.”
(Robert Firth)
Reply all
Reply to author
Forward
0 new messages