Debugging [was REBOL/Zine]
[1/5] from: ryanc:iesco-dms at: 13-Mar-2002 10:22
Hi!
[riusa--email--it]
wrote:
> Hi all, I have a problem:
>
> I wish to interrupt a program when it is running, using something like:
>
> print "DEBUG: "
> ask
>
You got to be careful here because 'ask takes an argument, and it will
snatch one from the next line if it has to.
> At this point, I want to analyze the variables used by my software,
> example:
>
> DEBUG: print myVar
Now 'print is one of the few functions in rebol that does not return a
value, so the above line will cause an error. The functions you really want
to use for debugging are '?? and 'probe. They both return their argument, so
they are easy to just insert into most places. '?? is a little dum with
anything except simple words, so dont use it with anything that has a "/" or
a ":" in it.
>
> where myVar is a variable previously defined in the software. But...
> Rebol tell me the variable does not exist! I think because this break
> (instruction "ask") create a new context, different from the one used
> by the program while it is running. What can I do to evaluate the
> instructions inserted in the "ask" block?
>
> Thanks!
>
My guess is that the original assignment of MyVar is not being evaluated.
Check that this is actually occuring with a 'probe, like so:
probe MyVar: "Im evaluated!"
Contexts should'nt bother you too much unless you play with to-string,
context, or make object!.
Enjoy! --Ryan
[2/5] from: riusa:email:it at: 14-Mar-2002 10:13
I'm sorry, I made a mistake when I wrote my email.
When I wrote:
DEBUG: print myVar
it was not an assignement, but I meant I was in debugging session! (my
mistake, sorry!).
However, I made some tests, and it seems functioning.
You let me discover another rebol function: "??"
which is the difference from "probe" and "??" (I objtain the same
results!).
Thank you for your help!
--
Prendi GRATIS l'email universale che... risparmia: http://www.email.it/f
Sponsor:
VolaSMS, il software pi=F9 completo per inviare e ricevere SMS dal tuo PC
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=276&d=14-3
[3/5] from: ryanc:iesco-dms at: 14-Mar-2002 10:28
Specifically this is the difference...
>> source ??
??: func [
{Prints a variable name followed by its molded value. (for debugging)}
'name
][
print either word? :name [rejoin [name ": " mold name: get name]] [mold
:
name]
:name
]
>> source probe
probe: func [
{Prints a molded, unevaluated value and returns the same value.}
value
][
print mold :value :value
]
>>
So one difference is probe evaluates its argument, whereas
?? captures the argument without evaluation and attempts to
print its word along with its value. The little tick mark does in
??'s function spec grabs a value without evaluating it like normal.
A common example...
>> ?? b: 5
b:
== 5
>> probe b: 5
5
== 5
>>
As you see ?? printed out the set-word! b: and returned 5, where
probe printed 5 and returned 5. This suprise result that happens with
?? occurs becuase it the set-word b action does not happen until after ??
has
returned its value--which is the set-word b.
There is an issue with paths! that occurs becuase they are processed
differently than regular words somehow that prevents them from being
evaluated as easily. I will leave it at that.
Have fun!
--Ryan
[riusa--email--it]
wrote:
[4/5] from: ingo::2b1::de at: 15-Mar-2002 0:11
Hi Ryan,
Ryan Cole wrote:
<...>
> So one difference is probe evaluates its argument, whereas
> ?? captures the argument without evaluation and attempts to
<<quoted lines omitted: 13>>
> ?? occurs becuase it the set-word b action does not happen until after ??
> has returned its value--which is the set-word b.
This discription is a little bit misleading: in the case of '?? b: is
printed, but 5 isn't returned by '??, 5 is returned because it didn't
get eaten, and was the last value on the line, as can be seen in this
extended example.
>> b
** Script Error: b has no value
** Near: b
>> ?? b: 7
b:
== 7
>> b
** Script Error: b has no value
** Near: b
>> probe b: 7
7
== 7
>> b
== 7
>> ?? b:
b:
== b:
>> ?? b
b: 7
== 7
So,
'probe can be used to print the value of _any_ expression,
'?? normally only makes sense with words, but you get the added
benefit of being told the name of the word.
Kind regards,
Ingo
[5/5] from: ryanc:iesco-dms at: 14-Mar-2002 17:20
Ingo,
I beg to differ, my description was not "a little misleading," it was
completely incorrect! Well, not wholy incorrect, but part about the set-word
eventually getting evaluated was absolutely incorrect.
This is a relief to me, because it was starting to bother me when I discovered
that other types were not getting evaluated upon return as I expected, and that
set-word was starting to appear to be some strange exception. I must have
dropped into console about 5 different times today throwing path!'s set-path!'s
function!'s op!'s and whatever I could think of at ??, each time scratching my
head while pondering the mechanics of the black box.
I really appreciate the correction.
--Ryan
Ingo Hohmann wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted