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

World: r3wp

[Core] Discuss core issues

[unknown: 5]
23-Feb-2008
[9289]
Is there an easy way to remove double blocks from a block.  So that 
something that looks like [[something]] looks like [something]?  
If not shouldn't we have something like this in REBOL as a mezz function?
Henrik
23-Feb-2008
[9290x2]
this has been discussed before, but I think the solution has scrolled 
out of view a long time ago...
R3 can do it using the new methods that loops can use, I believe.
[unknown: 5]
23-Feb-2008
[9292]
Are you saying it can't be done until R3?
Henrik
23-Feb-2008
[9293x3]
it can easily be done. the simplest way is:
form [[1][2][3]]
but it has limitations
[unknown: 5]
23-Feb-2008
[9296]
Can you expland on the limitations?
Henrik
23-Feb-2008
[9297x3]
you lose bindings and it won't work on series inside the blocks inside 
the block.
oops, it should be to-block form [[1][2][3]]
there are better solutions, but that is the quickest one.
[unknown: 5]
23-Feb-2008
[9300]
That is how I do also Henrik, I would be interested in a better solution 
but I was thinking we need one to handle the blocks within blocks
Henrik
23-Feb-2008
[9301]
the only other way in R2 is to process each block one by one with 
a loop
[unknown: 5]
23-Feb-2008
[9302]
I can build the function to loop through a block looking for others 
but am curious about the effect on bindings.
Henrik
23-Feb-2008
[9303]
I think we made a 'flatten function once.
[unknown: 5]
23-Feb-2008
[9304x2]
good name
Tell me more about in what way you think the bindings will get lost.
Henrik
23-Feb-2008
[9306x2]
with FORM you always lose bindings
try searching for flatten in AltME. plenty of references to it, I 
can see here.
[unknown: 5]
23-Feb-2008
[9308x2]
But I can only think that bindings would be lost for those blocks 
assigned as a value to a word
Seems it would still be useful for data taken from a stream of string 
data
Henrik
23-Feb-2008
[9310]
I can't calculate in my head when exactly the bindings are lost, 
so I would suggest simply experimenting in the console.
[unknown: 5]
23-Feb-2008
[9311]
Yeah I definately think that would be the case for set-words that 
contain block values but should be no problem on passing block data 
to set-words that are currently not set.
Gregg
23-Feb-2008
[9312]
flatten: func [blk [block!] /local res rule value] [
    	res: copy []

     rule: [some [into rule | set value skip (append res :value)]]
    	parse blk rule
    	res
    ]
[unknown: 5]
23-Feb-2008
[9313x2]
Here is a function for when you just want part of the block's flattened 
for when you reduce a bunch of data and want to use select on the 
data:

semi-flat: func [blk /local blk2][
    while [not tail? blk][
        if block? blk/1 [
            blk2: copy blk/1
            insert remove blk blk2
            blk: next next blk
        ]
    ]
    blk: head blk
]
>> data: [[1 ["record1"]] [2 ["record2"]] [3 ["record3"]]]
== [[1 ["record1"]] [2 ["record2"]] [3 ["record3"]]]
>> semi-flat data
== [1 ["record1"] 2 ["record2"] 3 ["record3"]]
>> select data 2
== ["record2"]
>> select data 3
== ["record3"]
Anton
23-Feb-2008
[9315x3]
Paul, you can avoid copy blk/1 by using change/part.

And perhaps better to continue processing the data when blk/1 is 
not a block.
semi-flat: func [blk][
    while [not tail? blk][
        blk: either block? blk/1 [
            change/part blk blk/1 1
        ][
	    next blk
	]
    ]
    head blk
]

semi-flat [[1 ["one"]] [2 ["two"]] "other data"]
You can also use until instead of while:
semi-flat: func [blk][
    until [
	tail? blk: either block? blk/1 [
            change/part blk blk/1 1
        ][
	    next blk
	]
    ]
    head blk
]
[unknown: 5]
23-Feb-2008
[9318x2]
Yes Anton, thanks.
Anton, both of those functions you provided didn't seem to achieve 
what I was intending to do which was to format the block for easy 
selecting using 'select.
Anton
23-Feb-2008
[9320]
My example data contains "other data" which is probably confusing 
you, sorry.
[unknown: 5]
25-Feb-2008
[9321x3]
Anyone know what the discussions are regarding extending the alias 
function in REBOL3?  I have a bit ugly function that does something 
like that now.  What I'm talking about is the ability to alias for 
example find/only or find/case or instead of just find so that no 
refinement has to be supplied.  I submitted a wish for this some 
time ago and hoped it would make it in REBOL3 but don't know what 
is intended regarding that.
I checked the alpha and noticed that it still says it doesn't allow 
path! for its word argument.
Probably should move this question to R3 group
james_nak
26-Feb-2008
[9324]
Gregg, thanks I will look into the ICS method.
Louis
26-Feb-2008
[9325]
I have a script that sends out a newsletter to several hundred people. 
Sometimes (often) the mail server will disconnect before all the 
emails are sent. What is the best way to make the script reconnect 
and continue sending?
[unknown: 5]
26-Feb-2008
[9326x10]
Here is a little function I made to handle a situation I often find 
myself in.  Say you got three words and want to do something if one 
of the words has a value other than false or none.  But you may want 
to do something else if two words have a true value or maybe all 
three and then if also if none have a value such as a default.  This 
is a very flexible function I created to allow you to do that:
evals: func [blk blk2 /local r i l][
    r: 0
    i: 0
    l: length? blk2: reverse blk2
    foreach item blk [if get item [r: r + (2 ** i)] i: i + 1]
    while [l > 0][
        if r > (2 ** (l - 3)) [return first blk2]
        blk2: next blk2
        l: l - 1
    ]
    last blk2: head blk2
]
Now say you have some locals in a function that you want to check 
for any combination of them being used.  The evals function will 
let you do that.
the 'blk argument would be the locals (assuming that 'evals is a 
subfunction of  our function) that you want to pass to the evals 
function and the 'blk2 would be what to return if those values are 
true.  So for example, if I have the following locals in my function:

/any /only  


and say I have a default value of "default" that I want to return 
if /any or /only is not used.  Therefore, I pass the following:

evals [any only]["default" "any" "only" "any and only"]


it would then process the result.  This can be a very handy function.
>> any: true
== true
>> only: true
== true
>> evals [any only]["default" "any" "only" "any&only"]
== "any&only"
>> any: false
== false
>> only: true
== true
>> evals [any only]["default" "any" "only" "any&only"]
== "only"
>> any: false
== false
>> only: none
== none
>> evals [any only]["default" "any" "only" "any&only"]
== "default"
Pretty cool, eh?
the function shouldn't be used on more than three values just yet 
as I need to work on it a bit more to get it just right - I keep 
overlooking something.
ahhh I didn't subtract the values
[unknown: 5]
27-Feb-2008
[9336x3]
This is probably more practical:
evals: func [blk blk2 /local i r ][
    r: i: 0
    foreach item blk [if get item [r: r + (2 ** i)] i: i + 1]
    return select blk2 to-integer r
    select blk2 0
]
then you just supply the second block with the desired options you 
want combined.