quasiquoting in R?
Oct. 28th, 2009 12:46 am
< gusl > I have a function 'fun' to which I want to pass the name of another
function 'f'. The name of 'f' is to be printed and then 'f' is to be
called. [00:40]
< gusl > I'm wondering whether I want to pass the name of the function... or
whether it's possible to pass the function itself, and get 'fun' to
compute its name. [00:41]
< gusl > I thought about using quote, but realized that it can't help
me... since it's not a quasiquote [00:43]
I'm not very hopeful of a solution along these lines... Fortunately, it's rare than I miss Lisp features (at least ever since I stopped using Java).
---
UPDATE: eval saved the day! It's still a bit cumbersome, since I need to call 'parse'.
eval(parse(text="square(5)"))
eval(parse(text="square"))(5) Also, the #R channel has a bot named "eval"!
(no subject)
Date: 2009-10-28 02:12 pm (UTC)Wakka wakka
Date: 2009-10-28 04:58 pm (UTC)function fun(f, ...) if f==add: print 'add' return f(...) if f==sub: print 'sub' return f(...) if f==mul: print 'mul' return f(...) print 'I don't recognized this function. It looks pretty awesome though. Please be to teaching me its name.' die()The more people that use it, the more knowledgeable it becomes. :-)
And for bonus credit, you could have the user enter the name of the function and store it to disk. Ohman. The possibilities.
(no subject)
Date: 2009-10-29 06:09 pm (UTC)(no subject)
Date: 2009-10-29 06:15 pm (UTC)If you can do the same for semantic identity, you could build a (more effective) "auto-refactor" function. :-) Ah, automatic programming...