Re: [julia-users] Re: Converting an expression to the function

2015-10-22 Thread Jānis Erdmanis
That looks neat :) On Thursday, October 22, 2015 at 8:44:15 PM UTC+3, Stefan Karpinski wrote: > > Doing it with strings and parsing is not necessary (and will make all good > Lispers very sad). You should splice and expression object into a function > definition and eval instead: > > julia> ex =

Re: [julia-users] Re: Converting an expression to the function

2015-10-22 Thread Alex Ames
Thanks Stefan, I knew there was a cleaner way. Looks like I need to study Exprs further. As a side-note, Janis, you may want to check out the ForwardDiff package, which allows for cheap, precise derivative evaluation. On Thursday, Octobe

Re: [julia-users] Re: Converting an expression to the function

2015-10-22 Thread Stefan Karpinski
Doing it with strings and parsing is not necessary (and will make all good Lispers very sad). You should splice and expression object into a function definition and eval instead: julia> ex = :(2x + y) :(2x + y) julia> @eval f(x,y) = $ex f (generic function with 1 method) julia> f(3,4) 10 On Th

[julia-users] Re: Converting an expression to the function

2015-10-22 Thread Alex Ames
There may be a slicker way to do this, but this should work: julia> fngen(expr,fn) = eval(parse(string(fn)* "=" * string(expr))) fngen (generic function with 1 method) julia> expr = :(x + y) :(x + y) julia> fngen(expr,:(f(x,y))) func (generic function with 1 method) julia> f(2,2) 4 On Thursday