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

2014-09-19 Thread Zouhair Mahboubi
Thanks Stefan, esc does the trick :)
I'll have to find a better way to copy/paste from ipython notebookds.

creating pull request in the scipy_2014_julia :)



On Sunday, September 14, 2014 5:13:41 PM UTC-7, David P. Sanders wrote:



 El domingo, 14 de septiembre de 2014 14:28:47 UTC-5, Zouhair Mahboubi 
 escribió:

 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


 I'm glad you find the tutorial useful!

 But it's certainly far from perfect, and certainly needs some 
 modifications, which I will be happy to implement if you send a Pull 
 Request!


  


 He has in there an example of macros. I was playing around with that and 
 I ran into a case where I don't understand why the expanded code ends up 
 introducing what seems to be a local variable. And this depends solely on 
 whether `expr2` contains `i += 1` or `i = i + 1`.

 Can someone take the time to explain why i one case the macro expansion 
 introduces a local variable? And how would one get around that in this case?

 Thanks,
 -z


 In [111]:

 macro until(expr1, expr2)

 quote

 #:(

 while !($expr1)  # code interpolation

 $expr2

 end

 #)

 end

 end

  

 In [122]:

 expr1 = 

 quote

 i = 0

 @until i==10 begin

 print(i)

 i += 1

 end

 end;

 expr2 = 

 quote

 i = 0

 @until i==10 begin

 print(i)

 i = i + 1

 end

 end;

 In [123]:

 eval(expr1)

 0123456789

 In [124]:

 eval(expr2)

 i not defined
 while loading In[124], in expression starting on line 1

  in anonymous at In[122]:4


 In [125]:

 macroexpand(expr1)

 div style=position: absolute; height: 30px; w
 ...



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

2014-09-14 Thread David P. Sanders


El domingo, 14 de septiembre de 2014 14:28:47 UTC-5, Zouhair Mahboubi 
escribió:

 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


I'm glad you find the tutorial useful!

But it's certainly far from perfect, and certainly needs some 
modifications, which I will be happy to implement if you send a Pull 
Request!


 


 He has in there an example of macros. I was playing around with that and I 
 ran into a case where I don't understand why the expanded code ends up 
 introducing what seems to be a local variable. And this depends solely on 
 whether `expr2` contains `i += 1` or `i = i + 1`.

 Can someone take the time to explain why i one case the macro expansion 
 introduces a local variable? And how would one get around that in this case?

 Thanks,
 -z


 In [111]:

 macro until(expr1, expr2)

 quote

 #:(

 while !($expr1)  # code interpolation

 $expr2

 end

 #)

 end

 end

  

 In [122]:

 expr1 = 

 quote

 i = 0

 @until i==10 begin

 print(i)

 i += 1

 end

 end;

 expr2 = 

 quote

 i = 0

 @until i==10 begin

 print(i)

 i = i + 1

 end

 end;

 In [123]:

 eval(expr1)

 0123456789

 In [124]:

 eval(expr2)

 i not defined
 while loading In[124], in expression starting on line 1

  in anonymous at In[122]:4


 In [125]:

 macroexpand(expr1)

 div style=position: absolute; height: 30px; w
 ...