Reputation: 580
I'm debugging a script which doesn't behave like I wished;
I'm writing a small debug utility function, which would print the 'word followed by its value. I wrote this:
debug: func [x] [print rejoin ['x " => " x] wait 0.5 ]
And, in my code, I'd like to call it simply like this:
phrase: "beer is good"
mots: parse phrase " "
debug phrase
foreach mot mots [
debug mot
;do something...
]
and I would dream that it would output on the console something like:
phrase => "beer is good"
mot => "beer"
mot => "is"
mot => "good"
but I can't find a way to retrieve the variable's original name, that is, its name out of the scope of the function.
Upvotes: 0
Views: 70
Reputation: 454
If you look at your 'debug function and compare it to the source of '??, you'll see what you would have needed to do differently:
??: func [
{Prints a variable name followed by its molded value. (for debugging)}
'name
][
print either word? :name [head insert tail form name reduce [": " mold name: get name]] [mold :name]
:name
]
Upvotes: 2
Reputation: 580
I had not searched enough...
?? variable
does what I needed.
>> ? ??
USAGE:
?? 'name
DESCRIPTION:
Prints a variable name followed by its molded value. (for debugging)
?? is a function value.
ARGUMENTS:
name -- (Type: any)
Upvotes: 0