r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[RAMBO] The REBOL bug and enhancement database

[unknown: 5]
24-Nov-2006
[2223x2]
before you turn on trace just do this:
echo %trace.txt
Henrik
24-Nov-2006
[2225]
still outputs to console. I'd like to avoid that.
[unknown: 5]
24-Nov-2006
[2226x2]
oh I see
I never tried it - or had need to without console output
Henrik
24-Nov-2006
[2228]
well, I'm not sure how useful trace is to me anyway.
Gabriele
24-Nov-2006
[2229x4]
chris, that is nice too.
about trace, if you need a count you can probably just use the STATS 
function.
however, in a trace a call to a slow function will count the same 
as a call to a fast function.
(second stats/eval should be the number of function calls)
[unknown: 5]
24-Nov-2006
[2233x2]
wow I just looked at stats on the latest view 2.7.1 and never noticed 
all the options for it before.
Yeah that is very useful Gabriele.
Anton
25-Nov-2006
[2235x6]
Paul, I don't share your concern about using ALL as a refinement 
of switch. I don't see that "killing the global ALL function" is 
a risk here. We are all aware of the danger of accidentally leaking 
words.
The advantage is we gain the freedom to use any word we like for 
the user interface.
Gabriele, slight optimization, swap these two lines:
            cases: next cases
            unless all [break]
Also, does this line:
	code: clear [ ]
mean that switch can't be used recursively ?
Chris' version looks pretty good too. (He just needs to document 
it properly.. :P)
Chris, what about [throw] ?
Gabriele
25-Nov-2006
[2241]
calling switch recursively - hmm, indeed it will be a problem. then 
i prefer chris' version which can avoid the allocation if not needed.
Anton
25-Nov-2006
[2242]
Yes, Chris' first line now seems clear to me. :)
Chris
25-Nov-2006
[2243x2]
Indeed I did abbreviate the function header.
Re. recursive, if you were to make block! [] instead of clear [] 
- I guess it's a difference in resultant garbage: with 'make the 
block becomes unbound when a subsequent switch is called, while with 
clear the cleared values become unbound.
[unknown: 5]
25-Nov-2006
[2245x5]
do we even need 'all - I mean I think we should just make that the 
default for switch and leave select to do the light lifting.
here is a switch that defaults to 'all
switch: func [
    "Finds all choices and evaluates what follows each."
    [throw]
    value "Value to search for."
    cases [block!] "Block of cases to search."
    /default case "Default case if no others are found."
    
][  
    default: copy []
    while [cases][
        if cases: find cases value [
            append default first cases: find cases block! 
        ]
    ]
    if not empty? default [case: default]
    do case    
]
Select is by far more efficient to use for single choices.
What I found interesting with stats/evals is that "block: copy []" 
is more efficient than "block: make block []"  I would not have expected 
that.
Chris
25-Nov-2006
[2250x3]
Only issue here is that it passes over empty values.  switch/default 
[1 []][print "one"]
Try this:
switch: func [value cases /default case][
    default: make block! []
    while [cases: find/tail cases value][
        either cases: find cases block! [
            case: append default first cases
        ][break]
    ]
    do case
]
[unknown: 5]
25-Nov-2006
[2253]
mine doesn't skip over the empty value it gives an error on it - 
which is actually useful if you ask me - I don't see any purpose 
to have an empty case passed to the switch - this way we know if 
we coded something incorrectly.
Chris
25-Nov-2006
[2254]
It's an issue if you're building a script incrementally and want 
an empty placeholder...
[unknown: 5]
25-Nov-2006
[2255x9]
Oh I see the error you talking about
not error rather the skip
yeah that isn't good
I'd rather have an error in that case
actually yours skips over it to
no it doesn't.  I like yours Chris
That is the approach I think we should take with Switch.
I would only suggest instead of using the make block! that you use 
 'copy [].
I saw the latest 2.7.2 notes - good job everyone.  Looks like switch 
might be a dead issue for now since the previous changes look like 
they were implemented.
Anton
25-Nov-2006
[2264]
Yes, what is the reasoning behind using  MAKE BLOCK! []  instead 
of  COPY []  ?  It appears to me that COPY evaluates faster.
Chris
25-Nov-2006
[2265]
No reason really, it was the first method that came to mind.
Anton
25-Nov-2006
[2266]
COPY looks about 12% faster (for allocating empty blocks).
Chris
25-Nov-2006
[2267]
; I guess this is moot, but a slight variation of my prior 'switch:
switch: func [[throw] value cases /default case][
    default: copy [] 
    while [
        all [
            cases: find/tail cases value 
            cases: find cases block!
        ]
    ][case: append default first cases]
    do case
]
Maxim
25-Nov-2006
[2268x3]
I know this rollback alot of lines, but I always marvel at  how Carl 
can reduce the size of code as he does.  He's been meditating about 
REBOL (throgh all of ancestors) for soooo long, it seems he can speak 
in rebol, "natively"  ;-)
unless is a nice addition to standard rebol, I know use it alll the 
time.
Paul, the interim releases are meant as "please test this" by all 
accounts.  IIRC view 1.3 had a few rollback based on user feedback 
of new features wreaking havoc on too many stuff.
[unknown: 5]
25-Nov-2006
[2271]
So do we want to approach switch then as being /all by default?  
To me it seems to make much more sense and I liked Chris's implentation 
of that switch.
Gabriele
26-Nov-2006
[2272]
switch is now native, which allows avoiding the allocation/copying 
(because the native does not have the BREAK problem)