Re: [julia-users] macro: with

2016-10-09 Thread Tom Breloff
Heh... it took a google search to figure out where I put it. https://github.com/tbreloff/CTechCommon.jl/blob/master/src/macros.jl#L113-L155 On Sun, Oct 9, 2016 at 12:19 PM, Ben Lauwens wrote: > Hi Tom > > I am interested. I am building a macro mimicking how iterator

[julia-users] macro: with

2016-10-09 Thread Ben Lauwens
Hi Tom I am interested. I am building a macro mimicking how iterator blocks are transformed in a state-machine in C# (as an alternative to Tasks) and this is one of the (many) thinks I have to solve. Can you point me to the source? Thanks Ben

[julia-users] macro: with

2016-09-07 Thread Tom Breloff
Hey all... I just threw together a quick macro to save some typing when working with the fields of an object. Disclaimer: this should not be used in library code, or in anything that will stick around longer than a REPL session. Hopefully it's self explanatory with this example. Is there a good

[julia-users] Macro to generate equivalent types

2016-05-19 Thread Tom Breloff
I have a pattern that I frequently use, and I'm considering writing a macro to automate it, but figured I'd check if it exists already. I frequently want to have the equivalent of an existing type functionally, but I want to be able to either dispatch on it or include additional fields for

Re: [julia-users] Macro as decorators

2016-05-09 Thread Kevin Squire
Possibly. Do you have a specific example in mind? That will probably get you a less ambivalent answer. :-) Cheers, Kevin On Monday, May 9, 2016, Ford Ox wrote: > Is it possible to write macro that will work as python decorator?

[julia-users] Macro as decorators

2016-05-09 Thread Ford Ox
Is it possible to write macro that will work as python decorator?

Re: [julia-users] Macro expansion for ccall with tuple argument

2016-04-07 Thread Yichao Yu
> and I programmed it as > julia> macro do_ccall(f,args...) > :(ccall(f,Int,$(ntuple(i->Int,length(args))),args...)) end I belive the arguments should be a tuple expression which you can generate with Expr(:tuple, [Int for i in 1:length(args)]...) > julia> macroexpand(:(@do_ccall(f,1,2,3))) >

[julia-users] Macro expansion for ccall with tuple argument

2016-04-07 Thread Laurent Bartholdi
Hi, I'm trying to understand macro expansion, and am a bit stuck. I would like, in distilled form, to have a macro "@do_ccall" which calls its argument with Int type. Thus I would like julia> macroexpand(:(@do_ccall(f,1,2,3))) :(ccall(f,Int,(Int64,Int64,Int64),args...)) and I programmed it as

Re: [julia-users] Macro hygiene issue

2016-03-02 Thread Cedric St-Jean
Thank you, that solved it. On Wed, Mar 2, 2016 at 10:54 AM, Yichao Yu wrote: > On Wed, Mar 2, 2016 at 10:51 AM, Cedric St-Jean > wrote: > > Hi, I have a situation that looks a bit like this: > > > > module A > > function foo end > > end > > > >

[julia-users] macro esc nested @everywhere issue

2016-02-18 Thread thr
Hi, I can't explain the behaviour of this: macro wtf1() return esc( :(begin @show a @everywhere const b = a @show b end)) end macro wtf2() return esc( :(begin @show c const d = c @show d

[julia-users] macro to exclude code depending on VERSION

2015-11-12 Thread andrew cooke
when you're writing code that uses macros, supporting different versions of julia seems to be more complex than normal. in particular, things like: if VERSION > XX # code with macros here end don't work as expected, because macro expansion occurs before runtime evaluation. so the macros

Re: [julia-users] macro to exclude code depending on VERSION

2015-11-12 Thread andrew cooke
ah, great. i won't make a new package then. thanks. On Thursday, 12 November 2015 09:30:21 UTC-3, Yichao Yu wrote: > > https://github.com/JuliaLang/julia/issues/7449 > https://github.com/JuliaLang/Compat.jl/pull/131 > https://github.com/JuliaLang/julia/issues/5892 > > On Thu, Nov 12, 2015

Re: [julia-users] macro to exclude code depending on VERSION

2015-11-12 Thread Yichao Yu
https://github.com/JuliaLang/julia/issues/7449 https://github.com/JuliaLang/Compat.jl/pull/131 https://github.com/JuliaLang/julia/issues/5892 On Thu, Nov 12, 2015 at 7:23 AM, andrew cooke wrote: > > when you're writing code that uses macros, supporting different versions of >

Re: [julia-users] macro to exclude code depending on VERSION

2015-11-12 Thread Seth
...and I just discovered Requires.jl. Fantastic stuff. On Thursday, November 12, 2015 at 8:55:23 PM UTC-8, Seth wrote: > > This could be useful to me :) > > I have a couple of functions that require JuMP but I don't want to add > JuMP to my REQUIRE file. My usual tactic of checking

Re: [julia-users] macro to exclude code depending on VERSION

2015-11-12 Thread Seth
This could be useful to me :) I have a couple of functions that require JuMP but I don't want to add JuMP to my REQUIRE file. My usual tactic of checking isdefined(:JuMP) won't work because JuMP uses macros that are evaluated prior to runtime. However, I was unable to make the following code

Re: [julia-users] Macro definition and call environments

2015-10-15 Thread Stefan Karpinski
On Thu, Oct 15, 2015 at 8:28 AM, wrote: > - Do these global variables also refer to function calls like time(), > println() within a macro?? Yes, time and println are just const global bindings to generic function objects. I am kind of confused how to think of the

[julia-users] Macro definition & call environments

2015-10-14 Thread juliatylors
Hi, can someone explain what macro definition environment and macro call environment? - I was reading the following page: http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#man-metaprogramming - it says in the Hygiene section : Local variables are then renamed to be

[julia-users] Macro definition and call environments

2015-10-14 Thread juliatylors
Hi, can someone explain what macro definition environment and macro call environment? - I was reading the following page: http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#man-metaprogramming - it says in the Hygiene section : "Local variables are then renamed to be

[julia-users] Macro to generate function signature

2015-04-30 Thread David Gold
I'm working (in 3.7) on a function that takes two functions f and g as inputs, merges all non-conflicting methods of f and g into one function h, and returns h. I'm trying to use macros to generate the signatures of each method for h: macro argsgen(typle, n::Int64) y = eval(:($typle))

Re: [julia-users] Macro to generate function signature

2015-04-30 Thread Isaiah Norton
The reduced case is: h((x1::Int64,x2::Int64)...) = x1+1 Which doesn't work, because the ... conflicts with the vararg syntax (the error message is admittedly not very good). I would suggest to generate the entire function from your macro, in which case you can just splice the tuple in and

[julia-users] Macro with varargs

2015-04-23 Thread Kuba Roth
This is my first time writing macros in Julia. I've read related docs but could not find an example which works with the arbitrary number of arguments. So in my example below the args... works correctly with string literals but for the passed variables it returns their names and not the values.

[julia-users] macro aliases? Can macro have the same assignment like temp = f::Function?

2014-12-31 Thread 良无
I know there are type aliases and function assignment. I find that a macro call is like Expr(:macrocall, symbol(@time),.) And we can embed a macro inside a macro, but it looks really uncomfortable to me. Thanks.

[julia-users] Macro scoping (or hygiene?) problems

2014-12-30 Thread Tomas Lycken
I’m doing some metaprogramming for Interpolations.jl, and I’m getting stuck at an error that I think is due to scoping issues in my nested quotes, and I’ve stared at this for so long now I’m not getting anywhere. I can do the following matching(d) = quote println(Matching: , $d) end

[julia-users] macro expansion for @until

2014-09-14 Thread Zouhair Mahboubi
New Julia user here :) Following the scipy/julia tutorial by D. Sanders and playing around with Macros http://nbviewer.ipython.org/github/dpsanders/scipy_2014_julia/blob/master/Metaprogramming.ipynb He has in there an example of macros. I was playing around with that and I ran into a case

Re: [julia-users] macro expansion for @until

2014-09-14 Thread Stefan Karpinski
You need to call esc on the expressions to provide macro hygiene. Sorry for the brief reply, but let me know if that helps. Btw, did you mean to include output from macroexpand above? If so, it doesn't seem to have gotten included. On Sun, Sep 14, 2014 at 9:28 PM, Zouhair Mahboubi

[julia-users] macro for generating functions with optional arguments

2014-05-08 Thread Kevin Squire
In your example, nothing is of type Nothing, which is not a MyType, so the assignment fails. Tim, for kw arguments, is it true that new functions are specialized for each type? I'm thought that it wouldn't, which would cause the variable to be an actual Union type if declared as such, and

[julia-users] Macro leads to slow code(?!)

2014-03-15 Thread andrew cooke
i have no idea what is happening here. please can someone explain why these give such different results? thanks, andrew cat Memory.jl immutable Fast{U:Unsigned} i::U end +{U:Unsigned}(a::Fast{U}, b::Fast{U}) = Fast{U}(a.i $ b.i) immutable Slow{I:Unsigned} i::I end for (name, op)