[julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-17 Thread Randy Zwitch
I've seen this type of function generation in other packages, and wanted to try it for myself. This file in Twitter.jl has 5 functions with the same overall structure: https://github.com/randyzwitch/Twitter.jl/blob/master/src/help.jl Here's what I ended up doing, which works, but I've got no i

Re: [julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-17 Thread Jacob Quinn
Can you just do funcname = (:get_help_configuration, :get_help_languages, :get_help_privacy, :get_help_tos, :get_application_rate_limit_status) endpoint = ("help/configuration.json", "help/languages.json", "help/privacy.json", "help/tos.json", "application/rate_limit_status.json") for (func, en

Re: [julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-17 Thread Randy Zwitch
It would appear so...I swear that I tried that, but I guess I didn't try that permutation! So what's it about the @eval macro that doesn't allow for regular string interpolation, that I have to use the string() function instead of an inline $? On Monday, November 17, 2014 9:50:55 PM UTC-5, Jac

Re: [julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-17 Thread elextr
On Tuesday, November 18, 2014 12:59:50 PM UTC+10, Randy Zwitch wrote: > > It would appear so...I swear that I tried that, but I guess I didn't try > that permutation! > > So what's it about the @eval macro that doesn't allow for regular string > interpolation, that I have to use the string() fu

Re: [julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-18 Thread Mike Innes
The basic reason for this is that it's fairly common to write something like: quote let x = 5 "x is $x" end end |> eval #> "x is 5" Where the $x referred to is the one available in the context of the created expression. If strings were treated similarly to other code here you'd have to wr

Re: [julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-18 Thread elextr
On Tuesday, November 18, 2014 7:40:53 PM UTC+10, Mike Innes wrote: > > The basic reason for this is that it's fairly common to write something > like: > > quote > let x = 5 > "x is $x" > end > end |> eval #> "x is 5" > But to do what the OP wants I think you can do "x is $($x)" (but I d

Re: [julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-18 Thread Mike Innes
Ah ok, that's a nice trick too – I didn't know you could do that (although it makes perfect sense). Note that this also constructs the string at runtime, though. On 18 November 2014 12:13, wrote: > > > On Tuesday, November 18, 2014 7:40:53 PM UTC+10, Mike Innes wrote: >> >> The basic reason for

Re: [julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-18 Thread Randy Zwitch
Thanks for all of the input everyone, I think I get what's going on now! On Tuesday, November 18, 2014 7:19:44 AM UTC-5, Mike Innes wrote: > > Ah ok, that's a nice trick too – I didn't know you could do that (although > it makes perfect sense). > > Note that this also constructs the string at run

Re: [julia-users] Metaprogramming: what's going on here/is there a better way?

2014-11-18 Thread elextr
On Tuesday, November 18, 2014 10:19:44 PM UTC+10, Mike Innes wrote: > > Ah ok, that's a nice trick too – I didn't know you could do that (although > it makes perfect sense). > > Note that this also constructs the string at runtime, though. > If x is a string constant a "sufficiently smart" (tm)