Re: [julia-users] Re: Debug printing a “value” and its “symbol”
Have you met @show? On 4 January 2015 at 11:10, wrote: > I think you need a macro, something like: > > macro printvar(var) >return :(print($(string(var))); print("="); println($var)) > end > > julia> a=2 > 2 > > julia> @printvar a > a=2 > > Cheers > Lex > > On Sunday, January 4, 2015 8:48:27 PM UTC+10, Arch Call wrote: >> >> I frequently find myself writing Julia snippet scripts like this: >> >> >> vara = 33 >> >> varb = vara * 14 >> >> varc = varb * 77 >> >> println(“varb = “, varb) #--debug print >> >> println(“varc = “, varc) #--debug print >> >> >> I would like to eliminate having to enter the variable name twice >> >> in the debug print lines by using a function. >> >> >> I have tried all kinds of variations of a debug print function like: >> >> >> function debugprint(somevar) >> >> println(“ = ”, somevar) >> >> end >> >> >> What can I put in place of “” to get the actual Symbol of the >> variable being passed to debugprint? >> >
Re: [julia-users] Re: Debug printing a “value” and its “symbol”
julia> begin @show vara = 33 @show varb = vara * 14 @show varc = varb * 77 end vara = 33 = 33 varb = vara * 14 = 462 varc = varb * 77 = 35574 35574 On Sun, Jan 4, 2015 at 5:47 AM, Mike Innes wrote: > Have you met @show? > > On 4 January 2015 at 11:10, wrote: > >> I think you need a macro, something like: >> >> macro printvar(var) >>return :(print($(string(var))); print("="); println($var)) >> end >> >> julia> a=2 >> 2 >> >> julia> @printvar a >> a=2 >> >> Cheers >> Lex >> >> On Sunday, January 4, 2015 8:48:27 PM UTC+10, Arch Call wrote: >>> >>> I frequently find myself writing Julia snippet scripts like this: >>> >>> >>> vara = 33 >>> >>> varb = vara * 14 >>> >>> varc = varb * 77 >>> >>> println(“varb = “, varb) #--debug print >>> >>> println(“varc = “, varc) #--debug print >>> >>> >>> I would like to eliminate having to enter the variable name twice >>> >>> in the debug print lines by using a function. >>> >>> >>> I have tried all kinds of variations of a debug print function like: >>> >>> >>> function debugprint(somevar) >>> >>> println(“ = ”, somevar) >>> >>> end >>> >>> >>> What can I put in place of “” to get the actual Symbol of the >>> variable being passed to debugprint? >>> >> >
Re: [julia-users] Re: Debug printing a “value” and its “symbol”
Reading the code, there is also a `indent` option, i thought it accepted a boolean, but not, I find it very unintuitive: dump(io::IO, x, n::Int, indent) = xdump(dump, io, x, n, indent) julia> dump(:(1 + 1 * 3 - 4^7), 10, false) Expr false head: Symbol call false args: Array(Any,(3,)) false1: Symbol - false2: Expr false head: Symbol call false args: Array(Any,(3,)) false1: Symbol + false2: Int32 1 false3: Expr false head: Symbol call false args: Array(Any,(3,)) false1: Symbol * false2: Int32 1 false3: Int32 3 false typ: Any false typ: Any false3: Expr false head: Symbol call false args: Array(Any,(3,)) false1: Symbol ^ false2: Int32 4 false3: Int32 7 false typ: Any false typ: Any And once can't use this argument, as a keyword argument: julia> dump(:(1 + 1 * 3 - 4^7), indent="--->") ERROR: function dump does not accept keyword arguments Keyword arguments are slow? Or why are the not used that much throughout the API? El domingo, 4 de enero de 2015 09:53:35 UTC-6, Ismael VC escribió: > > julia> begin >@show vara = 33 >@show varb = vara * 14 >@show varc = varb * 77 >end > vara = 33 = 33 > varb = vara * 14 = 462 > varc = varb * 77 = 35574 > 35574 > > > On Sun, Jan 4, 2015 at 5:47 AM, Mike Innes wrote: > >> Have you met @show? >> >> On 4 January 2015 at 11:10, wrote: >> >>> I think you need a macro, something like: >>> >>> macro printvar(var) >>>return :(print($(string(var))); print("="); println($var)) >>> end >>> >>> julia> a=2 >>> 2 >>> >>> julia> @printvar a >>> a=2 >>> >>> Cheers >>> Lex >>> >>> On Sunday, January 4, 2015 8:48:27 PM UTC+10, Arch Call wrote: I frequently find myself writing Julia snippet scripts like this: vara = 33 varb = vara * 14 varc = varb * 77 println(“varb = “, varb) #--debug print println(“varc = “, varc) #--debug print I would like to eliminate having to enter the variable name twice in the debug print lines by using a function. I have tried all kinds of variations of a debug print function like: function debugprint(somevar) println(“ = ”, somevar) end What can I put in place of “” to get the actual Symbol of the variable being passed to debugprint? >>> >> >