0

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.

Pierre
  • 530
  • 5
  • 13

2 Answers2

2

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
]
Respectech
  • 454
  • 4
  • 13
0

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)
Pierre
  • 530
  • 5
  • 13
  • On the topic of taking lit-word params, there is a subtle difference between passing parameters as lit-words and as get-words: ["Why doesn't Rebol 3 honor quoted function parameters that are parenthesized?"](http://stackoverflow.com/questions/14532596/why-doesnt-rebol-3-honor-quoted-function-parameters-that-are-parenthesized) – HostileFork says dont trust SE Jul 25 '13 at 20:11