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

World: r3wp

[I'm new] Ask any question, and a helpful person will try to answer.

Paul
14-Jun-2009
[2996]
Because the argument to index? is supposed to be a series and 'none 
is not a series.
mhinson
14-Jun-2009
[2997]
Then should FIND return an empty series if the target is not found? 
rather than none?  I thought none was a special case & might be handled 
differently by some functions that expect specific types.
Paul
14-Jun-2009
[2998x2]
yes find will return none if something isn't found.
But see Find returns none BASED on a series argument.  You were suppling 
'none as the argument.
Henrik
14-Jun-2009
[3000]
One can say that FIND limits its input to series! to eliminate errors 
as early as possible. Imagine if FIND accepted NONE and we had some 
intricate series of FINDs on a single block 'a:

find find find/reverse find a 'e string! 'f integer!
== none


If 'a is a dynamic block (not known when you write the code) where 
is the error?


It's not a great example, but it raises the question of how forgiving 
you want your functions to be, when you write them. I consider that 
you generally want to catch errors as early as possible, to avoid 
having to write "forgiving" code that can take up space and complicate 
things and worst of all, make the code much harder to debug. But 
it's only one school of thought.
mhinson
14-Jun-2009
[3001x2]
I see now HenriK, thanks for the explanation. So it encourages you 
to write code that is as deterministic as possiable and also make 
it more likely that you will need to understand your data fully too.
ANY & ALL are quite hard, but I think I am getting it..  This confused 
me for a while, but now I understand.
a: b: c: d: []

any [ do[a: 1 false] do[ all[ do[b: 2 false] do[c: 3 true]] true] 
do[ d: 4 true]]
print rejoin["a,b,c,d=" a "," b "," c "," d]
This is what I think is happening.  

a is set but as the block returns false the ANY block evaluation 
continues

b is set within the nested ALL block & as it returns false the ALL 
block evaluation stops

the do which contains the ALL block returns true so the ANY block 
evaluation stops
Izkata
14-Jun-2009
[3003]
Yes; ANY is a shortcut for OR'ing vaues together, and ALL is a shortcut 
for AND.
Henrik
14-Jun-2009
[3004]
I use ANY and ALL a lot because they can be handy in situations where 
an EITHER can be too cumbersome, such as inline result output for 
printing:

print any [select names name "No Name Found"]

In other cases they take up more space than an EITHER.
Tomc
14-Jun-2009
[3005x2]
unlike a series of and/or  any/all will stop evaulating conditions 
at the first condition that deternims the result
so the first true for any  and the first false for all
Gregg
14-Jun-2009
[3007x2]
Mike, memoizing has never caused me any technical problems. Just 
be sure to document it clearly.
I take that back, I've messed up a couple times and created uncontrolled 
growth in the memoized data. You do have to watch out for that. :-)
Oldes
15-Jun-2009
[3009]
instead of:
any [ do[a: 1 false] ]
why not to use just:
any [ (a: 1 false) ]
mhinson
15-Jun-2009
[3010]
That is interesting Oldes.  I thought I tried something like that, 
but now I see I must have been confused about what the () do.

so does the ANY cause the () to evaluate its contents?  If I just 
put [(true)] it is not evaluated, but all[(true)] is.   Then again 
to-logic [(false)] is not evaluated. There must be a trick I am missing 
here I think.  Thanks,
Gregg
15-Jun-2009
[3011x5]
Yes, ANY and ALL evaluate the block.
And parens are evaluated by default.
>> first [(true)]
== (true)
>> type? first [(true)]
== paren!
>> type? first reduce [(true)]
== logic!
One of my biggest AHA moments in REBOL was seeing that there is no 
code, only data that *may be* evaluated, and knowing when evaluation 
occurs is key (and easy to trip over :-).
Using blocks and *not* evaluating their contents--perhaps "deferring 
evalutation" is a better way to say it--is also a powerful aspect 
of REBOL. Being able to prevent parens from being evaluated is a 
good example.
mhinson
15-Jun-2009
[3016x2]
I think I would love to know when evaluation occurs.. So far I mostly 
just have to test every fragment of code I write & if I am lucky 
I guess right first time. I am slowly getting better at it, but I 
would say it is often a bit of a mystery.
I have submitted a script to the Library.  http://www.rebol.org/view-script.r?script=cisco-extract.r

Its purpose (apart from learning Rebol) is to read Cisco config files 
& present the interface information in a tab separated text file.
mhinson
17-Jun-2009
[3018]
Hi, I have done a bit with fairly basic parse expressions, but I 
am now trying to understand more.

Am I right to think that ALL SOME & ANY are the only controls of 
this type?  Or am I missing another in the set?

Do ALL & ANY work in the parse dialect the same way that they do 
described above?  Thanks.
BrianH
17-Jun-2009
[3019]
ALL is not an operation in the parse dialect. ANY and SOME are looping 
operations in parse.
mhinson
17-Jun-2009
[3020x2]
Ah. that is why I am getting erros with it.  I thought I was just 
using it wrongly. Thanks.
The errors are rather cryptic
BrianH
17-Jun-2009
[3022]
ANY is like regex *, SOME is like regex +, OPT is like regex ?.
mhinson
17-Jun-2009
[3023]
is there any way to get rebol help on the parse dialect?   like ? 
PRINT etc please?
BrianH
17-Jun-2009
[3024]
You have to look online, sorry.
mhinson
17-Jun-2009
[3025]
ok.  I really like the ? help functions. While learning they help 
a great deal.  Thanks.
BrianH
17-Jun-2009
[3026]
Unfortunately, parsing is considered a hard subject. Learning PARSE 
might take some time if you haven't had experience or taken a class 
in parsing before, even when you read the online docs.
Pekr
17-Jun-2009
[3027]
Do you think proposed parse enhancement will slow parse performance?
BrianH
17-Jun-2009
[3028x3]
Some of them will speed up parse performance, others will have little 
effect outside of their specific operation.
Performance should improve overall with the parse enhancements, in 
theory.
There were almost no changes to existing operations. Most of the 
proposals were for new operations that would replace complex code 
patterns, and those would be faster, easier and less buggy than the 
code patterns they replace.
mhinson
17-Jun-2009
[3031]
I had a really usefull walk-through of Parse with Maxim a few weeks 
ago here.  I wouldn't say Parse has been any harder for me to learn 
about than any other aspect I have delved into so far, in fact I 
found the GUI stuff the most confusing to get ahead with.
Pekr
17-Jun-2009
[3032]
new GUI should be much better to understand ...
mhinson
17-Jun-2009
[3033x2]
I started looking at the R3 Gui too.  I am mostly intrested in drawing 
my own graphics on screen, controled by a bit of maths & trig, but 
with real-time interaction from sliders etc.  I suspect this is not 
the sort of thing that newbies are expected to do, but writing text 
in different fonts on coloured buttons dosn't do anything for me.. 

I am finding that using any part of Rebol makes it easier to understand 
the discussion here & get more in tune with what behaviour to expect.
I have been working on my Parse understanding and came up with this:
parse/all {aX--baX~~a--aX~~} [some
  [
    "a" h: some[ 
      [ 
        ["--" :h copy result to "--" (print result) thru "a" h:]
        |["~~" :h copy result to "~~" (print result) thru "a" h:]
      ] |[skip]
    ]
  ]
]
I am extracting the text between "a" and either "--" or "~~" 

Is my method a reasonable aproach or is there a simpler or more readable 
way to do this sort of thing please?
Ladislav
17-Jun-2009
[3035]
here is my way:
parse/all {aX--baX~~a--aX~~} [
	"a"
	some [
	    s:
		any [
		    t: ["--" | "~~"] (result: copy/part s t print result) break
			| skip
		]
		thru "a"
	]
	to end
]
Izkata
17-Jun-2009
[3036x2]
If the empty one doesn't need to be recorded as empty:
parse/all {aX--baX~~a--aX~~} [                             
   some [

      ["a" some ["--" break | "~~" break | X: (print X/1) skip] | skip]
   ]
]
Mine'll also only grab one character at a time, so {abbb--} would 
need something extra
Graham
18-Jun-2009
[3038]
If it's a fixed length format .. why bother use parse and just use 
copy/part ?
mhinson
18-Jun-2009
[3039]
Thanks for the examples, I will be digesting them for a while I think.

I started looking at a real life problem where the ending sequence 
of what I wanted to extract was two different things (". " OR "." 
newline), that led me to look at this sort of structure & try to 
understand how parse rules can be adapted.  My example is educational 
only, not from real life. It was intended to be a short example of 
non-fixed length format with multiple cases to extract and 2 different 
end-of-data-to-extract markers. I think a better example of what 
I intended should have XX as the data to extract in one case. {aX--baX~~a--aX~~aXX~~} 
perhaps.   Thanks.
Izkata
18-Jun-2009
[3040]
Righto, here's my updated one - good practice for me, too, I rarely 
use parse like this:

parse/all {aX--baX~~a--aX~~aXX~~} [                              
          

   some [                                                           
             

      ["a" S: some [E: ["--" | "~~"] (print copy/part S E) break | skip] 
      | skip] 
   ]
]
Steeve
18-Jun-2009
[3041]
Lot of ways with parse...

content: complement charset "-~"
parse/all {aX--baX~~a--aX~~aXX~~} [

   some [                                                           
             

      thru #"a" opt [copy result some content ["--" | "~~"] (print result)]
   ]
]
mhinson
19-Jun-2009
[3042]
It is strange this parse learning..  I look at these rules & understand 
what is happening.  BUT I try to write my own without looking at 
these & I always get confused again.  It dosn't seem very complex, 
but it does seem very easy to get wrong. Does any one have any tricks 
for formatting the code in a way that helps keep track of what the 
logic is doing?
Graham
19-Jun-2009
[3043x2]
Have you looked at brett handley's visual parse thing?
http://www.rebol.org/view-script.r?script=parse-analysis-view.r
mhinson
20-Jun-2009
[3045]
I remeber looking at this before, but I couldn't work out how to 
use it... With a bit of luck I will understand it now, although it 
does look quite complex. Thanks.