Re: [racket] Functions as symbols

2011-10-07 Thread Eli Barzilay
6 hours ago, Mark Carter wrote: > I would obtain the answer 3. Is there any way I can do this? The > following works, but I'm wondering if it's the best way: > (eval `(apply ,sym '(1 2))) > A more basic question would be: is there any way I can convert from > '+ to + - i.e. a symbol to a function?

Re: [racket] Functions as symbols

2011-10-07 Thread Hendrik Boom
On Fri, Oct 07, 2011 at 08:53:20AM +0100, Mark Carter wrote: > I would like to treat a symbol as a function, and apply it to some arguments. > In other words, if I did something like > (define sym '+) > (apply '+ '(1 2)) > I would obtain the answer 3. Is there any way I can do this? The following

Re: [racket] Functions as symbols

2011-10-07 Thread Richard Cleis
The long answer to your question depends on how you are using the capability. You don't have to form the whole expression before evaluating it, and you don't need to use apply. For example, you can define a symbol in racket, then run the program: #lang racket/base (define sym '+) [run the abov

Re: [racket] Functions as symbols

2011-10-07 Thread Stephan Houben
Hi Mark, On 10/07/2011 09:53 AM, Mark Carter wrote: A more basic question would be: is there any way I can convert from '+ to + - i.e. a symbol to a function? Either just (eval '+) or (namespace-variable-value '+). Please note that this looks up the symbol in the namespace as indicated by th

[racket] Functions as symbols

2011-10-07 Thread Mark Carter
I would like to treat a symbol as a function, and apply it to some arguments. In other words, if I did something like (define sym '+) (apply '+ '(1 2)) I would obtain the answer 3. Is there any way I can do this? The following works, but I'm wondering if it's the best way: (eval `(apply ,sym '(1