[julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
Thanks for the replies.

I have been comparing ansi c syntax and julia lately, so I had to naturally 
ask, why julia doesn't define functions in the same way ansi c does?
foo(args...) begin # ansi c style definition
 #some code
end

If julia would define functions like this, a *keyword for one line block* 
(one line begin end) could be introduced, lets say '->' 

You could then
foo(args..) -> args # one liner
 (args) -> args # natural anonymous function
if true -> return x # one line if

These came onto my mind in first 10 secs, maybe there are *more* useful 
cases.

But then I realised that this definition would clash with macros, because 
you would have no more any function keyword.
So you would have to either 
*(1)* make every callable with '@' in name a macro automatically
  - In this case you would have to make a special case for macro definition 
since right now, when compiler sees @foo, he tries to evaluate that. So the 
special rule would have to be something like this
@foo(args...)begin ... end  #macro definition, because block follows
(@foo(args...)begin ... end #not macro definition, because closed in (), 
macro will be evaluated
@foo(args...) -> ...# macro def
(@foo(args...) -> ...   # not macro def ...
*(2) *or make every callable both function or macro
  - That's what I was asking about.

So that was basically my though process. 
I guess my ideas were too simple as always so it would be not possible to 
implement it anyway, even  tho it looks kinda cool ( at least to me ). :)





Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Yuri Vishnevsky
I might be wrong here, but you could imagine "unifying" macros and 
functions, allowing people to call any function as a macro by prepending a 
@, or calling any macro as a function by omitting it.

I don't know whether this would be useful, but it's how I read Ford's 
question.


On Sunday, June 5, 2016 at 12:36:30 PM UTC-4, Stefan Karpinski wrote:
>
> On Sun, Jun 5, 2016 at 11:41 AM, Scott Jones  > wrote:
>
>> On the other hand, that would prevent having a function with the same 
>> name as a macro.
>
>
> This is the primary reason. When you define a macro named "@foo", the 
> transformation function for it is bound to the non-standard symbol "@foo":
>
> julia> macro foo(x) esc(x) end
> @foo (macro with 1 method)
>
> julia> getfield(Main, Symbol("@foo"))(:(x + y))
> :($(Expr(:escape, :(x + y
>
>
> You can actually define a macro with the function syntax by using eval to 
> splice in a macro-like name for the function:
>
> julia> @eval function $(Symbol("@foo"))(x) esc(x) end
> @foo (macro with 1 method)
>
> julia> macroexpand(:(@foo x + y))
> :(x + y)
>
>
> So the syntax for macro definition could be changed to something like this:
>
> function @foo(x) esc(x) end
>
>
> However this short form:
>
> @foo(x) = esc(x)
>
>
> would not work since it's ambiguous with having a macro call be the left 
> hand side of an assignment.
>


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Stefan Karpinski
On Sun, Jun 5, 2016 at 11:41 AM, Scott Jones 
wrote:

> On the other hand, that would prevent having a function with the same name
> as a macro.


This is the primary reason. When you define a macro named "@foo", the
transformation function for it is bound to the non-standard symbol "@foo":

julia> macro foo(x) esc(x) end
@foo (macro with 1 method)

julia> getfield(Main, Symbol("@foo"))(:(x + y))
:($(Expr(:escape, :(x + y


You can actually define a macro with the function syntax by using eval to
splice in a macro-like name for the function:

julia> @eval function $(Symbol("@foo"))(x) esc(x) end
@foo (macro with 1 method)

julia> macroexpand(:(@foo x + y))
:(x + y)


So the syntax for macro definition could be changed to something like this:

function @foo(x) esc(x) end


However this short form:

@foo(x) = esc(x)


would not work since it's ambiguous with having a macro call be the left
hand side of an assignment.


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Scott Jones
I think it may just boil down to being a historical artifact - until 
recently (and only in v0.5, AFAIK), macros were handled rather differently 
from functions.
Now that macros actually act like functions, and have different methods (of 
course limited to types known at parse time, symbols, numeric literals, 
etc.),
it might be more consistent to simply have macros defined as functions.

I.e. instead of:
macro foo(x)
  return :( $(string("Prefix",x)))
end
you could have
foo(x) = :( $(string("Prefix",x)))

On the other hand, that would prevent having a function with the same name 
as a macro.

On Sunday, June 5, 2016 at 10:48:51 AM UTC-4, Rafael Fourquet wrote:
>
> I think the OP's question is not about the difference between a macro 
> and a function, but rather about the syntactic way of defining a 
> macro: if a macro can be seen as a function taking an expression and 
> returning another one, why can't we just define a macro with the 
> standard function syntax (i.e. without the macro keyword), and inform 
> the compiler that we want to use it as a macro only at the call site, 
> by invoking it prepended with the @ sign. 
>


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Steven G. Johnson
Macro calls are syntactically distinct from function calls in part because they 
are evaluated at parse time, before the compiler can know the bindings of 
variables (which would be necessary in order to determine whether f(x) is a 
function call or a macro call without the @). 

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
Exactly.

On Sunday, June 5, 2016 at 4:48:51 PM UTC+2, Rafael Fourquet wrote:
>
> I think the OP's question is not about the difference between a macro 
> and a function, but rather about the syntactic way of defining a 
> macro: if a macro can be seen as a function taking an expression and 
> returning another one, why can't we just define a macro with the 
> standard function syntax (i.e. without the macro keyword), and inform 
> the compiler that we want to use it as a macro only at the call site, 
> by invoking it prepended with the @ sign. 
>


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Rafael Fourquet
I think the OP's question is not about the difference between a macro
and a function, but rather about the syntactic way of defining a
macro: if a macro can be seen as a function taking an expression and
returning another one, why can't we just define a macro with the
standard function syntax (i.e. without the macro keyword), and inform
the compiler that we want to use it as a macro only at the call site,
by invoking it prepended with the @ sign.


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Erik Schnetter
In the hope of bringing a derailed conversation back on track:

Ford, maybe you are not asking a Julia but a general computer science
question. In this case: A macro is strictly more powerful than a function,
so in principle, every function can be replaced by a macro. There are
various "technical" details to get right (i.e. scoping, preventing name
clashes) that make this non-trivial.

However, a much stronger argument for functions is current compiler
technology. For example, Julia compiles a whole function at a time, which
makes it impossible to have recursive macros. Also, since Julia can inline
functions, but won't "anti-inline" common expressions, this would lead to
rather bad code. Thus, from a practical point of view, you can use macros
instead of functions only for small functions without sacrificing
efficiency.

In fact, when you write a macro in Julia, you'll often find that you need
to break a large macro into functions, and then substitute calls to these
functions instead of the code you'd like to generate.

-erik



On Sun, Jun 5, 2016 at 9:06 AM, Ford O.  wrote:

> ...
> I think I gave you all help I could, to understand the question. I am not
> going to explain it over and over and over.
>
>
> On Sunday, June 5, 2016 at 2:40:31 PM UTC+2, Tamas Papp wrote:
>>
>> I am sorry --- I did not realize you had anger management issues.  In
>> any case, consider the example in the section of the manual I linked,
>> with macros and functions:
>>
>> macro time_mac(ex)
>>   return quote
>> local t0 = time()
>> local val = $ex
>> local t1 = time()
>> println("elapsed time: ", t1-t0, " seconds")
>> val
>>   end
>> end
>>
>> function time_fun(ex)
>>   return quote
>> local t0 = time()
>> local val = $ex
>> local t1 = time()
>> println("elapsed time: ", t1-t0, " seconds")
>> val
>>   end
>> end
>>
>> Then observe the output of
>>
>> time_fun(:(foo()))
>>
>> macroexpand(:(@time_mac(foo()))
>>
>> On Sun, Jun 05 2016, Ford O. wrote:
>>
>> > Don't make me angry.
>> >
>> > I have read that chapter more than 5 times.
>> > You could also read my question 5 times.
>> >
>> > I am asking why do we have to specify macro and function with different
>> > keyword, when compiler exactly knows whether we are calling macro or
>> > function.
>> >
>> > Example for ...:
>> > callable foo(e::Expr) = :()
>> > @foo 2 + 2
>> > foo(2 + 2)
>> > # two versions of foo callable are compiled, one as macro, one as
>> function
>> >
>> > Does the *macro *keyword have any significance for compiler?
>> >
>> > On Sunday, June 5, 2016 at 1:38:32 PM UTC+2, Tamas Papp wrote:
>> >>
>> >> Sorry for linking a local version of the manual -- still, you could
>> >> probably have found it with a bit of effort, but it appears that you
>> are
>> >> adamant in your refusal to read it.
>> >>
>> >> I would say that the most important reasons is that macros have
>> special
>> >> conventions because of hygiene, see
>> >>
>> http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene
>> >>
>> >> Some languages (eg Common Lisp) have the same namespace for macros and
>> >> functions, Julia distinguishes them with @. So they are not as
>> seamless
>> >> as in CL, but at the same time they stand out and warn the reader that
>> >> source transformation is going on. There could be arguments for both
>> >> choices, but Julia chose this one.
>> >>
>> >> On Sun, Jun 05 2016, Ford O. wrote:
>> >>
>> >> > You got it wrong.
>> >> > In different words.
>> >> >
>> >> > Why do we need to specify macro and function block with macro and
>> >> function
>> >> > keyword? Isnt the '@' symbol enough?
>> >> >
>> >> > On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote:
>> >> >>
>> >> >> A macro is a function that is used to transform (a representation)
>> of
>> >> >> source code. Consequently, it is called when Julia evaluates your
>> >> >> function defintions, not at runtime. Please read
>> >> >> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html
>> where
>> >> >> you find examples.
>> >> >>
>> >> >> Regarding you example: it is unclear what you are trying to do, but
>> >> >> unless you use the macro keyword, you get an ordinary function, not
>> a
>> >> >> macro.
>> >> >>
>> >> >> On Sun, Jun 05 2016, Ford O. wrote:
>> >> >>
>> >> >> > What makes macro different from function?
>> >> >> >
>> >> >> > Why is it not possible to do:
>> >> >> > foo(e::Expr) = :()
>> >> >> > @foo x = x + 5
>> >> >> >
>> >> >> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote:
>> >> >> >
>> >> >> >  I think this deserves an own topic.
>> >> >> >
>> >> >> >  You should post here syntax that looks like duplicate or you
>> think
>> >> it
>> >> >> could use already existing keyword. (mark with # identical or #
>> >> >> replacement)
>> >> >> >  Rule of thumb - the less special syntax the better.
>> >> >> >
>> >> >> >  # identical
>> >> >> >  # replace ' , ' with ' ; ' in arrays ?
>> >> >> >  [1, 2, 3, 4]

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
...
I think I gave you all help I could, to understand the question. I am not 
going to explain it over and over and over.

On Sunday, June 5, 2016 at 2:40:31 PM UTC+2, Tamas Papp wrote:
>
> I am sorry --- I did not realize you had anger management issues.  In 
> any case, consider the example in the section of the manual I linked, 
> with macros and functions: 
>
> macro time_mac(ex) 
>   return quote 
> local t0 = time() 
> local val = $ex 
> local t1 = time() 
> println("elapsed time: ", t1-t0, " seconds") 
> val 
>   end 
> end 
>
> function time_fun(ex) 
>   return quote 
> local t0 = time() 
> local val = $ex 
> local t1 = time() 
> println("elapsed time: ", t1-t0, " seconds") 
> val 
>   end 
> end 
>
> Then observe the output of 
>
> time_fun(:(foo())) 
>
> macroexpand(:(@time_mac(foo())) 
>
> On Sun, Jun 05 2016, Ford O. wrote: 
>
> > Don't make me angry. 
> > 
> > I have read that chapter more than 5 times. 
> > You could also read my question 5 times. 
> > 
> > I am asking why do we have to specify macro and function with different 
> > keyword, when compiler exactly knows whether we are calling macro or 
> > function. 
> > 
> > Example for ...: 
> > callable foo(e::Expr) = :() 
> > @foo 2 + 2 
> > foo(2 + 2) 
> > # two versions of foo callable are compiled, one as macro, one as 
> function 
> > 
> > Does the *macro *keyword have any significance for compiler? 
> > 
> > On Sunday, June 5, 2016 at 1:38:32 PM UTC+2, Tamas Papp wrote: 
> >> 
> >> Sorry for linking a local version of the manual -- still, you could 
> >> probably have found it with a bit of effort, but it appears that you 
> are 
> >> adamant in your refusal to read it. 
> >> 
> >> I would say that the most important reasons is that macros have special 
> >> conventions because of hygiene, see 
> >> 
> http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene 
> >> 
> >> Some languages (eg Common Lisp) have the same namespace for macros and 
> >> functions, Julia distinguishes them with @. So they are not as seamless 
> >> as in CL, but at the same time they stand out and warn the reader that 
> >> source transformation is going on. There could be arguments for both 
> >> choices, but Julia chose this one. 
> >> 
> >> On Sun, Jun 05 2016, Ford O. wrote: 
> >> 
> >> > You got it wrong. 
> >> > In different words. 
> >> > 
> >> > Why do we need to specify macro and function block with macro and 
> >> function 
> >> > keyword? Isnt the '@' symbol enough? 
> >> > 
> >> > On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote: 
> >> >> 
> >> >> A macro is a function that is used to transform (a representation) 
> of 
> >> >> source code. Consequently, it is called when Julia evaluates your 
> >> >> function defintions, not at runtime. Please read 
> >> >> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html 
> where 
> >> >> you find examples. 
> >> >> 
> >> >> Regarding you example: it is unclear what you are trying to do, but 
> >> >> unless you use the macro keyword, you get an ordinary function, not 
> a 
> >> >> macro. 
> >> >> 
> >> >> On Sun, Jun 05 2016, Ford O. wrote: 
> >> >> 
> >> >> > What makes macro different from function? 
> >> >> > 
> >> >> > Why is it not possible to do: 
> >> >> > foo(e::Expr) = :() 
> >> >> > @foo x = x + 5 
> >> >> > 
> >> >> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
> >> >> > 
> >> >> >  I think this deserves an own topic. 
> >> >> > 
> >> >> >  You should post here syntax that looks like duplicate or you 
> think 
> >> it 
> >> >> could use already existing keyword. (mark with # identical or # 
> >> >> replacement) 
> >> >> >  Rule of thumb - the less special syntax the better. 
> >> >> > 
> >> >> >  # identical 
> >> >> >  # replace ' , ' with ' ; ' in arrays ? 
> >> >> >  [1, 2, 3, 4] 
> >> >> >  [1; 2; 3; 4] 
> >> >> > 
> >> >> >  # identical 
> >> >> >  # replace ' = ' with ' in ' in for loops ? 
> >> >> >  for i = 1:10 
> >> >> >  for i in 1:10 
> >> >> > 
> >> >> >  # replacement 
> >> >> >  # replace ' -> ' with ' = ' in anonymous functions ? 
> >> >> >  (a, b, c) -> a + b + c 
> >> >> >  (a, b, c) = a + b + c 
> >> >> 
> >> >> 
> >> 
> >> 
>
>

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Tamas Papp
I am sorry --- I did not realize you had anger management issues.  In
any case, consider the example in the section of the manual I linked,
with macros and functions:

macro time_mac(ex)
  return quote
local t0 = time()
local val = $ex
local t1 = time()
println("elapsed time: ", t1-t0, " seconds")
val
  end
end

function time_fun(ex)
  return quote
local t0 = time()
local val = $ex
local t1 = time()
println("elapsed time: ", t1-t0, " seconds")
val
  end
end

Then observe the output of

time_fun(:(foo()))

macroexpand(:(@time_mac(foo()))

On Sun, Jun 05 2016, Ford O. wrote:

> Don't make me angry.
>
> I have read that chapter more than 5 times.
> You could also read my question 5 times.
>
> I am asking why do we have to specify macro and function with different 
> keyword, when compiler exactly knows whether we are calling macro or 
> function.
>
> Example for ...:
> callable foo(e::Expr) = :()
> @foo 2 + 2
> foo(2 + 2)
> # two versions of foo callable are compiled, one as macro, one as function 
>
> Does the *macro *keyword have any significance for compiler?
>
> On Sunday, June 5, 2016 at 1:38:32 PM UTC+2, Tamas Papp wrote:
>>
>> Sorry for linking a local version of the manual -- still, you could 
>> probably have found it with a bit of effort, but it appears that you are 
>> adamant in your refusal to read it. 
>>
>> I would say that the most important reasons is that macros have special 
>> conventions because of hygiene, see 
>> http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene 
>>
>> Some languages (eg Common Lisp) have the same namespace for macros and 
>> functions, Julia distinguishes them with @. So they are not as seamless 
>> as in CL, but at the same time they stand out and warn the reader that 
>> source transformation is going on. There could be arguments for both 
>> choices, but Julia chose this one. 
>>
>> On Sun, Jun 05 2016, Ford O. wrote: 
>>
>> > You got it wrong. 
>> > In different words. 
>> > 
>> > Why do we need to specify macro and function block with macro and 
>> function 
>> > keyword? Isnt the '@' symbol enough? 
>> > 
>> > On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote: 
>> >> 
>> >> A macro is a function that is used to transform (a representation) of 
>> >> source code. Consequently, it is called when Julia evaluates your 
>> >> function defintions, not at runtime. Please read 
>> >> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where 
>> >> you find examples. 
>> >> 
>> >> Regarding you example: it is unclear what you are trying to do, but 
>> >> unless you use the macro keyword, you get an ordinary function, not a 
>> >> macro. 
>> >> 
>> >> On Sun, Jun 05 2016, Ford O. wrote: 
>> >> 
>> >> > What makes macro different from function? 
>> >> > 
>> >> > Why is it not possible to do: 
>> >> > foo(e::Expr) = :() 
>> >> > @foo x = x + 5 
>> >> > 
>> >> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
>> >> > 
>> >> >  I think this deserves an own topic. 
>> >> > 
>> >> >  You should post here syntax that looks like duplicate or you think 
>> it 
>> >> could use already existing keyword. (mark with # identical or # 
>> >> replacement) 
>> >> >  Rule of thumb - the less special syntax the better. 
>> >> > 
>> >> >  # identical 
>> >> >  # replace ' , ' with ' ; ' in arrays ? 
>> >> >  [1, 2, 3, 4] 
>> >> >  [1; 2; 3; 4] 
>> >> > 
>> >> >  # identical 
>> >> >  # replace ' = ' with ' in ' in for loops ? 
>> >> >  for i = 1:10 
>> >> >  for i in 1:10 
>> >> > 
>> >> >  # replacement 
>> >> >  # replace ' -> ' with ' = ' in anonymous functions ? 
>> >> >  (a, b, c) -> a + b + c 
>> >> >  (a, b, c) = a + b + c 
>> >> 
>> >> 
>>
>>



Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
Don't make me angry.

I have read that chapter more than 5 times.
You could also read my question 5 times.

I am asking why do we have to specify macro and function with different 
keyword, when compiler exactly knows whether we are calling macro or 
function.

Example for ...:
callable foo(e::Expr) = :()
@foo 2 + 2
foo(2 + 2)
# two versions of foo callable are compiled, one as macro, one as function 

Does the *macro *keyword have any significance for compiler?

On Sunday, June 5, 2016 at 1:38:32 PM UTC+2, Tamas Papp wrote:
>
> Sorry for linking a local version of the manual -- still, you could 
> probably have found it with a bit of effort, but it appears that you are 
> adamant in your refusal to read it. 
>
> I would say that the most important reasons is that macros have special 
> conventions because of hygiene, see 
> http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene 
>
> Some languages (eg Common Lisp) have the same namespace for macros and 
> functions, Julia distinguishes them with @. So they are not as seamless 
> as in CL, but at the same time they stand out and warn the reader that 
> source transformation is going on. There could be arguments for both 
> choices, but Julia chose this one. 
>
> On Sun, Jun 05 2016, Ford O. wrote: 
>
> > You got it wrong. 
> > In different words. 
> > 
> > Why do we need to specify macro and function block with macro and 
> function 
> > keyword? Isnt the '@' symbol enough? 
> > 
> > On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote: 
> >> 
> >> A macro is a function that is used to transform (a representation) of 
> >> source code. Consequently, it is called when Julia evaluates your 
> >> function defintions, not at runtime. Please read 
> >> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where 
> >> you find examples. 
> >> 
> >> Regarding you example: it is unclear what you are trying to do, but 
> >> unless you use the macro keyword, you get an ordinary function, not a 
> >> macro. 
> >> 
> >> On Sun, Jun 05 2016, Ford O. wrote: 
> >> 
> >> > What makes macro different from function? 
> >> > 
> >> > Why is it not possible to do: 
> >> > foo(e::Expr) = :() 
> >> > @foo x = x + 5 
> >> > 
> >> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
> >> > 
> >> >  I think this deserves an own topic. 
> >> > 
> >> >  You should post here syntax that looks like duplicate or you think 
> it 
> >> could use already existing keyword. (mark with # identical or # 
> >> replacement) 
> >> >  Rule of thumb - the less special syntax the better. 
> >> > 
> >> >  # identical 
> >> >  # replace ' , ' with ' ; ' in arrays ? 
> >> >  [1, 2, 3, 4] 
> >> >  [1; 2; 3; 4] 
> >> > 
> >> >  # identical 
> >> >  # replace ' = ' with ' in ' in for loops ? 
> >> >  for i = 1:10 
> >> >  for i in 1:10 
> >> > 
> >> >  # replacement 
> >> >  # replace ' -> ' with ' = ' in anonymous functions ? 
> >> >  (a, b, c) -> a + b + c 
> >> >  (a, b, c) = a + b + c 
> >> 
> >> 
>
>

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Tamas Papp
Sorry for linking a local version of the manual -- still, you could
probably have found it with a bit of effort, but it appears that you are
adamant in your refusal to read it.

I would say that the most important reasons is that macros have special
conventions because of hygiene, see
http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene

Some languages (eg Common Lisp) have the same namespace for macros and
functions, Julia distinguishes them with @. So they are not as seamless
as in CL, but at the same time they stand out and warn the reader that
source transformation is going on. There could be arguments for both
choices, but Julia chose this one.

On Sun, Jun 05 2016, Ford O. wrote:

> You got it wrong.
> In different words.
>
> Why do we need to specify macro and function block with macro and function 
> keyword? Isnt the '@' symbol enough?
>
> On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote:
>>
>> A macro is a function that is used to transform (a representation) of 
>> source code. Consequently, it is called when Julia evaluates your 
>> function defintions, not at runtime. Please read 
>> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where 
>> you find examples. 
>>
>> Regarding you example: it is unclear what you are trying to do, but 
>> unless you use the macro keyword, you get an ordinary function, not a 
>> macro. 
>>
>> On Sun, Jun 05 2016, Ford O. wrote: 
>>
>> > What makes macro different from function? 
>> > 
>> > Why is it not possible to do: 
>> > foo(e::Expr) = :() 
>> > @foo x = x + 5 
>> > 
>> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
>> > 
>> >  I think this deserves an own topic. 
>> > 
>> >  You should post here syntax that looks like duplicate or you think it 
>> could use already existing keyword. (mark with # identical or # 
>> replacement) 
>> >  Rule of thumb - the less special syntax the better. 
>> > 
>> >  # identical 
>> >  # replace ' , ' with ' ; ' in arrays ? 
>> >  [1, 2, 3, 4] 
>> >  [1; 2; 3; 4] 
>> > 
>> >  # identical 
>> >  # replace ' = ' with ' in ' in for loops ? 
>> >  for i = 1:10 
>> >  for i in 1:10 
>> > 
>> >  # replacement 
>> >  # replace ' -> ' with ' = ' in anonymous functions ? 
>> >  (a, b, c) -> a + b + c 
>> >  (a, b, c) = a + b + c 
>>
>>



Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
You got it wrong.
In different words.

Why do we need to specify macro and function block with macro and function 
keyword? Isnt the '@' symbol enough?

On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote:
>
> A macro is a function that is used to transform (a representation) of 
> source code. Consequently, it is called when Julia evaluates your 
> function defintions, not at runtime. Please read 
> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where 
> you find examples. 
>
> Regarding you example: it is unclear what you are trying to do, but 
> unless you use the macro keyword, you get an ordinary function, not a 
> macro. 
>
> On Sun, Jun 05 2016, Ford O. wrote: 
>
> > What makes macro different from function? 
> > 
> > Why is it not possible to do: 
> > foo(e::Expr) = :() 
> > @foo x = x + 5 
> > 
> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
> > 
> >  I think this deserves an own topic. 
> > 
> >  You should post here syntax that looks like duplicate or you think it 
> could use already existing keyword. (mark with # identical or # 
> replacement) 
> >  Rule of thumb - the less special syntax the better. 
> > 
> >  # identical 
> >  # replace ' , ' with ' ; ' in arrays ? 
> >  [1, 2, 3, 4] 
> >  [1; 2; 3; 4] 
> > 
> >  # identical 
> >  # replace ' = ' with ' in ' in for loops ? 
> >  for i = 1:10 
> >  for i in 1:10 
> > 
> >  # replacement 
> >  # replace ' -> ' with ' = ' in anonymous functions ? 
> >  (a, b, c) -> a + b + c 
> >  (a, b, c) = a + b + c 
>
>

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Tamas Papp
A macro is a function that is used to transform (a representation) of
source code. Consequently, it is called when Julia evaluates your
function defintions, not at runtime. Please read
file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where
you find examples.

Regarding you example: it is unclear what you are trying to do, but
unless you use the macro keyword, you get an ordinary function, not a
macro.

On Sun, Jun 05 2016, Ford O. wrote:

> What makes macro different from function?
>
> Why is it not possible to do:
> foo(e::Expr) = :()
> @foo x = x + 5
>
> On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote:
>
>  I think this deserves an own topic.
>
>  You should post here syntax that looks like duplicate or you think it could 
> use already existing keyword. (mark with # identical or # replacement)
>  Rule of thumb - the less special syntax the better.
>
>  # identical
>  # replace ' , ' with ' ; ' in arrays ?
>  [1, 2, 3, 4]
>  [1; 2; 3; 4]
>
>  # identical
>  # replace ' = ' with ' in ' in for loops ?
>  for i = 1:10
>  for i in 1:10
>
>  # replacement
>  # replace ' -> ' with ' = ' in anonymous functions ?
>  (a, b, c) -> a + b + c
>  (a, b, c) = a + b + c



[julia-users] Re: Uniform syntax

2016-06-05 Thread Steven G. Johnson


On Sunday, June 5, 2016 at 6:35:48 AM UTC-4, Ford O. wrote:
>
> What makes macro different from function?
>

Macros are executed at parse time.  Functions are executed at runtime. 


[julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
What makes macro different from function?

Why is it not possible to do:
foo(e::Expr) = :()
@foo x = x + 5

On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote:
>
> I think this deserves an own topic.
>
> *You* should post here syntax that looks like duplicate or you think it 
> could use already existing keyword. (mark with* # identical *or *# 
> replacement*)
> Rule of thumb - *the less special syntax the better*.
>
> # identical
> # replace ' , ' with ' ; ' in arrays ?
> [1, 2, 3, 4]
> [1; 2; 3; 4]
>
>
>
> # identical
> # replace ' = ' with ' in ' in for loops ?
> for i = 1:10
> for i in 1:10
>
>
>
>
> # replacement
> # replace ' -> ' with ' = ' in anonymous functions ?
> (a, b, c) -> a + b + c
> (a, b, c) = a + b + c
>