gusl: (Default)
[personal profile] gusl
< 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)
From: [identity profile] easwaran.livejournal.com
I would have thought that it's easier to pass the name and then have it find the function - presumably each name only corresponds to one function, but each function might correspond to multiple names, which would make going the other direction hard. Unless I'm misunderstanding something.

(no subject)

Date: 2009-10-29 06:09 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
I came to the same conclusion after I posted.

(no subject)

Date: 2009-10-29 06:15 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
However, one could make a function that searches in the list of functions (available in R through ls()) that is syntactically identical to your function.

If you can do the same for semantic identity, you could build a (more effective) "auto-refactor" function. :-) Ah, automatic programming...

Wakka wakka

Date: 2009-10-28 04:58 pm (UTC)
From: [identity profile] aisa0.livejournal.com
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.

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags