Re: [julia-users] Adding the same functionality / variables into many functions

2016-02-25 Thread Michael Borregaard
I am relieved to hear you what not use it in practice, I was trying really hard to grasp the utility of it :-) It is a very elegant piece of code, though. Den torsdag den 25. februar 2016 kl. 01.18.16 UTC+1 skrev Tom Breloff: > > I think he was just referring to the fact that it's "one more thin

Re: [julia-users] Adding the same functionality / variables into many functions

2016-02-24 Thread cdm
understood ... i was really focusing on this: "... essentially each macro introduces a new keyword." which is either true, or false ... and not having any real experience with the macro space i am assuming that it is true ... if it is true, then it seems reasonable to have the means to under

Re: [julia-users] Adding the same functionality / variables into many functions

2016-02-24 Thread Tom Breloff
I think he was just referring to the fact that it's "one more thing to remember". For the record, I would never actually use this macro, for reasons implied by Mauro, but there are other, similar uses that this strategy could be benficial. The choice (IMO) should come down to which is more intuiti

Re: [julia-users] Adding the same functionality / variables into many functions

2016-02-24 Thread cdm
interesting ... what facilities are available to survey and reason about this "keyword" space ? On Wednesday, February 24, 2016 at 11:05:34 AM UTC-8, Mauro wrote: > > ... essentially each macro introduces a new keyword. >

Re: [julia-users] Adding the same functionality / variables into many functions

2016-02-24 Thread Mauro
> this is awesome > > thanks! A small word of caution: macros can make it harder for others (or your future self) to read the code, as essentially each macro introduces a new keyword. Just something to consider when introducing a macro; awesome as they are. > On Wednesday, February 24, 2016 at 3

Re: [julia-users] Adding the same functionality / variables into many functions

2016-02-24 Thread Alex
this is awesome thanks! On Wednesday, February 24, 2016 at 3:32:48 PM UTC+1, Tom Breloff wrote: > > Enjoy: > > > julia> macro n(expr::Expr) >@assert expr.head == :function >s = expr.args[1].args[2] >if isa(s,Expr) && s.head == :(::) >s = s.args[

Re: [julia-users] Adding the same functionality / variables into many functions

2016-02-24 Thread Tom Breloff
Enjoy: julia> macro n(expr::Expr) @assert expr.head == :function s = expr.args[1].args[2] if isa(s,Expr) && s.head == :(::) s = s.args[1] end unshift!(expr.args[2].args, :(n = length($s))) esc(expr) end julia

[julia-users] Adding the same functionality / variables into many functions

2016-02-24 Thread Alex
Hi everybody, I have several functions operating on one dimensional vectors. Within each function the first thing I do is to define variable n holding the length of input vector x: n = length(x) Is that possible to factor out this pattern somehow from all functions definitions? (...like 't