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

World: r3wp

[Core] Discuss core issues

Chris
22-May-2007
[8182]
flatten: func [block [any-block!]][

    parse block [

         any [block: any-block! (change/part block first block 1) :block | 
         skip]

    ]
 
   head block
]
Henrik
23-May-2007
[8183x2]
and with greater speed but less accuracy:
>> load form [1 2 [3 4] 5 6]
and now I should of course have read what Graham posted...
BrianH
23-May-2007
[8185]
Don't assume that the parse is slow - you may be surprised.
Anton
23-May-2007
[8186]
Yes, and I wouldn't recommend the LOAD FORM way, it looks too brittle.
Henrik
24-May-2007
[8187x2]
does SORT/COMPARE not work in combination with /SKIP? it seems to 
happily ignore /SKIP here.
seems that using /ALL does not help.
Gregg
24-May-2007
[8189]
>> b: [1 2 3 4 5  5 4 3 2 1  7 6 5 4 3  3 4 5 6 7]
== [1 2 3 4 5 5 4 3 2 1 7 6 5 4 3 3 4 5 6 7]
>> bb: sort/compare/skip copy b 2 5
== [1 2 3 4 5 5 4 3 2 1 3 4 5 6 7 7 6 5 4 3]
>> bb: sort/compare/skip copy b 4 5
== [5 4 3 2 1 1 2 3 4 5 7 6 5 4 3 3 4 5 6 7]
Henrik
25-May-2007
[8190]
what if the record size is 2, consists of a binary and an object 
and you want to sort on a value in the object?
Sunanda
25-May-2007
[8191]
Here's one way -- though it assumes (for simplicity) that the binary 
is a string of equal length in all keys:


data: reduce ["z" make object! [key: 1] "y" make object! [key: 2] 
"z" make object! [key: 2]]
sort/all/skip/compare  data 2 func [a b][
     return (join a/1 a/2/key) < (join b/1 b/2/key)
    ]
probe data
Henrik
25-May-2007
[8192x5]
hmm... funny, I did exactly that code, but it would never recognize 
the b object in the compare function. will have to try again...
oh wait a minute. I see now :-)
I guess I don't after all. I still can't get it to recognize 'b. 
If I try to probe 'b inside the function, sorting just stops. probing 
'a works fine.
and the block checks out fine. it is properly arranged.
found the bug. (and I need more coffee)
Sunanda
25-May-2007
[8197]
There were problems with using all three refinements [ /all/compare/skip 
] together in earlier versions of REBOL. I believe they are fixed 
now.
Henrik
25-May-2007
[8198]
I think the compare feature is just a bit underdocumented.
Rebolek
25-May-2007
[8199x2]
Script error: REPLACE has no refinement called ONLY
I can use CHANGE/ONLY FIND ...
What do you think, skould I RAMBO it as a wish?
Henrik
25-May-2007
[8201]
rebolek, yeah, I think it would make sense to have that.
Rebolek
25-May-2007
[8202]
It's mezanine, so I'll try to figure out some fix and post it.
Henrik
25-May-2007
[8203]
cool
Rebolek
25-May-2007
[8204x3]
Hm, was easier than I thought :))
Posted
>> regexp "[hello-:-world-:-re]" "[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}"
== true
;))
BrianH
25-May-2007
[8207]
Anyone else want a regex compiler that generates parse rules? Semantically, 
regex is a (very) limited subset of parse so it shouldn't bee too 
hard.
Rebolek
25-May-2007
[8208x3]
I working on it right now. the above example is copied from console
some things are not implemented yet and there some small problems 
but I hope I can solve them
I was looking for something, but nothing seems to exist. So I started 
mine, I'll release some first version soon.
Gregg
25-May-2007
[8211]
http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=like.r
BrianH
25-May-2007
[8212x3]
The reason that regex compilers for REBOL are rare is that parse 
is more powerful than regex, and most people who start trying to 
implement regex usually learn enough about parse during the course 
of doing so that they switch to using parse instead :)
Still, if you want help, a tester or a second opinion, post your 
code on the Parse group and we will optimize it for you.
It's funny, there's no better optimizer than the members of this 
world trying to show off and one-up each other :)
Gregg
25-May-2007
[8215]
I love this community. One of my favorite things is the ML threads 
that optimize code and bring out different perspectives on design.
Terry
1-Jun-2007
[8216]
Hey... what's the code to prevent  the security from popping up in 
windows?  added -s to a shortcut, but not working?
Gabriele
1-Jun-2007
[8217]
-s should work...
Maxim
1-Jun-2007
[8218x8]
in 98% of cases I agree with what Brian just said about Parse being 
more powerfull than Regexp.  but in those 2% regexp is SO much more 
powerfull, that it still has its place.   now some of you will ask 
me to say when or why, (I know how we as rebolers think and like 
to challenge each other ;-)  but I cannot give an exact example, 
but having had to implement a few complex systems in both, I remember 
a few times in parse when I'd remember how a single char would replace 
2-3 lines of parse "tricks".
so, having a regexp WITHIN parse would be oh so incredible.  especially 
since Parse allows such an easy way to traverse data at such a fast 
rate.  having regexp to take "decisions" would scale pretty nicely. 
  OTOH having rebol to take decision could be an alternative too.
Parse is good at matching, but sometimes, a simple condition "means" 
something which is hellish to implement as a set of explicitely mutually-excluding 
matches.  regexp is a little easier in this case (note I use easier 
not in style or readability here... just in raw expressiveness).
if we could add a conditional within the dialect of parse directly 
(without using tricks, which I know many will be tempted to demonstrate, 
and many which I already know about) then parse itself would have 
another level of expressiveness IMHO.
one example could be to use the return value of evaluated parens 
as a "matched? or not" in order to continue in a parse rule.
this would allow us to make much simpler rules sometimes, especially 
when such decisions are not based on simple left to right loading 
of values, but sometimes based on interdependent values, which only 
take meaning once certain patterns have been loaded.
for example, not only the type and shape of data, but its actual 
value?  have I loaded enough of this, for this rule to qualify.  
is a specific attribute set to a mandatory value?  there are many 
such examples.
again, I know most patterns CAN be described using parse, but in 
many occasions, what could have been a simple parens with a decision 
and 2 or 3 very simple rules, ended up being a complex tree of tens 
or more rules, which have non obvious interdenpendencies and things 
like left entry recursions (I hope I make sense here) which are, 
well, slow(er) and hard to map in one's mind.
Terry
1-Jun-2007
[8226]
regexp should be shot
Chris
2-Jun-2007
[8227]
Max, could you flesh that out as a hypothetical example?
Maxim
2-Jun-2007
[8228]
are you asking me to give an example?
Chris
2-Jun-2007
[8229]
Sure, how would it look?
Maxim
2-Jun-2007
[8230x2]
well, I guess the best way would be to use parens within the parse 
block as a means to return if we should continue in this rule, (and 
maybe even based on type, how many items to skip!).
hum... you are asking my mind to shift from cgi and web site writing 
to parse rule generation.. hehe I'm a bit deep in the construction 
of Revault right now... with about 10 files opened and mapped in 
my mind ;-)