Please ignore this part:
julia> macro ≔(v, b)
e = Expr(:global, v)
:(global $e; $(esc(v)) = $(esc(b)))
As you can see even the end keyword is missing, so it would have made an
incomplete input error.
It was a mistake on my part I pasted an incomplete part of a prior version
of the macro of when I was testing it *sorry for the confusion.*
Even when you added the end keyword yourself, you can see that the second
line says e = Expr(:global, v) and then the third says: :(global $e;
$(esc(v)) = $(esc(b))), so global is repeating two times, the message ERROR:
syntax: invalid syntax in "global" declaration is because this duplication,
is like trying to type:
julia> x = 5
5
julia> let
global global x # ooops!
end
ERROR: syntax: invalid syntax in "global" declaration
in eval at boot.jl:263
You can see that before redefining the macro it works
just
as expected.
Ismael Venegas Castelló
*Data Analyst*
Cel. 044 55 6434 0229
[email protected]
Cerro San Francisco 357, C.P. 04200
Campestre Churubusco, Coyoacán
Ciudad de México
<http://t.sidekickopen35.com/e1t/c/5/f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJW7t5XX43Mx_82W1p1tN-8q-fZWW3LPXXH56dKBHf5NSPJF02?t=https%3A%2F%2Frichit.com.mx%2F&si=4656540167962624&pi=7cc818fa-ede0-4557-ed9e-a0be10678db6>
<https://www.facebook.com/richitsolution>
<http://t.sidekickopen35.com/e1t/c/5/f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJW7t5XX43Mx_82W1p1tN-8q-fZWW3LPXXH56dKBHf5NSPJF02?t=https%3A%2F%2Ftwitter.com%2Frichitsolution&si=4656540167962624&pi=7cc818fa-ede0-4557-ed9e-a0be10678db6>
<[email protected]>
Tel. 6718 1818
richit.com.mx
2016-01-06 16:55 GMT-06:00 Rob J. Goedman <[email protected]>:
> Hi Ismael,
>
> Just trying to learn from this thread, on both Julia 0.4.2 and 0.5 I get
> an error in the 2nd version of the macro:
>
> *julia> **≔(var, block) = @eval $var = $block*
> *≔ (generic function with 1 method)*
>
> *julia> *
>
> *julia> **@show :foo ≔ "some foo"; foo*
> :foo ≔ "some foo" = "some foo"
> *"some foo"*
>
> *julia> **@show :foo ≔ 42; foo*
> :foo ≔ 42 = 42
> *42*
>
> *julia> *
>
> *julia> **macro ≔(v, b)*
> * e = Expr(:global, v)*
> * :($e; $(esc(v)) = $(esc(b)))*
> *end*
> *@≔ (macro with 1 method)*
>
> *julia> *
>
> *julia> **@≔ foo :FOOL*
> *:FOOL*
>
> *julia> *
>
> *julia> **@≔ fooled :FOOLED; fooled*
> *:FOOLED*
>
> *julia> *
>
> *julia> **macro ≔(v, b)*
> * e = Expr(:global, v)*
> * :(global $e; $(esc(v)) = $(esc(b)))*
> *end*
> *@≔ (macro with 1 method)*
>
> *julia> *
>
> *julia> **@≔ bar "some bar"; bar*
> *ERROR: syntax: invalid syntax in "global" declaration*
> * in eval at ./boot.jl:265*
>
> *julia> *
>
> *julia> **@≔ bar 19; bar*
> *ERROR: syntax: invalid syntax in "global" declaration*
> * in eval at ./boot.jl:265*
>
> *julia> *
>
> *julia> **versioninfo()*
> Julia Version 0.5.0-dev+2021
> Commit bc1c18e (2016-01-06 17:45 UTC)
> Platform Info:
> System: Darwin (x86_64-apple-darwin15.3.0)
> CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
> WORD_SIZE: 64
> BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
> LAPACK: libopenblas64_
> LIBM: libopenlibm
> LLVM: libLLVM-3.3
>
> In addition to the ‘end’ line, is something else needed to make exporting
> to the global environment work?
>
> Regards,
> Rob
>
>
> On Jan 5, 2016, at 03:53, Ismael Venegas Castelló <[email protected]>
> wrote:
>
> You could use another similar operator like \coloneq:
>
> julia> ≔(var, block) = @eval $var = $block
> ≔ (generic function with 1 method)
>
> julia> @show :foo ≔ "some foo"; foo
> :foo ≔ "some foo" = "some foo"
> "some foo"
>
> julia> @show :foo ≔ 42; foo
> :foo ≔ 42 = 42
> 42
>
> julia> macro ≔(v, b)
> e = Expr(:global, v)
> :($e; $(esc(v)) = $(esc(b)))
> end
>
> julia> @≔ foo :FOO
> :FOO
>
> julia> @≔ foo :FOO; foo
> :FOO
>
> julia> macro ≔(v, b)
> e = Expr(:global, v)
> :(global $e; $(esc(v)) = $(esc(b)))
>
> julia> @≔ bar "some bar"; bar
> "some bar"
>
> julia> @≔ bar 7; bar
> 7
>
>
>
> El martes, 5 de enero de 2016, 3:18:07 (UTC-6), Julia Tylors escribió:
>>
>> Hi,
>>
>> How can i override the = operator?
>>
>> Thanks
>>
>> function ={T}(x::T,y::T)
>> ...
>> end
>>
>> didn't work
>>
>> Thanks
>>
>
>