Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] 'parse trick and 'unset

From: shannon:ains:au at: 17-Dec-2000 1:15

Anton wrote:
> Try this out: > line1: "Ju<li>e<><><<1234>" > id: [thru "<" 3 4 digits ">"] > rule: [a: some [id | [skip b:]] (print copy/part a b)] > parse line1 rule
Nice trick, I would never have thought of it. It will really be useful for 'extract rule checking (see my last post). I was surprised by the results of the following test though:
>> parse line1 rule
Ju<li>e<><>< == true
>> line2: "Jules<1234>ffg<5678>"
== "Jules<1234>ffg<5678>"
>> parse line2 rule
** Script Error: Invalid /part count: <1234>. ** Where: print copy/part a b Weird. After some stuffing around I discovered this was because 'a and 'b were still defined from the last operation, so the values need to be cleared. This is apparently not as easy as it would seem:
>> a: "" b: ""
== ""
>> parse line2 rule
** Script Error: Invalid /part count: . ** Where: print copy/part a b
>> a: none! b: none!
== none!
>> parse line2 rule
** Script Error: copy expected range argument of type: number series port. ** Where: print copy/part a b
>> a: [] b: []
== []
>> parse line2 rule
** Script Error: Invalid /part count: . ** Where: print copy/part a b Sascha wrote:
>> is there a trick to effectively destroy >> a variable from the shell's global namespace? >> (not found in manual..) >> many thanks >> Sascha.
That's what I wanted to know but just as I was going to post this I tried something:
>> ? unset
USAGE: UNSET word DESCRIPTION: Unsets the value of a word. UNSET is a native value. ARGUMENTS: word -- Word or block of words (Type: word block)
>> unset 'a unset 'b >> parse line2 rule
** Script Error: b has no value. ** Where: print copy/part a b
>> probe line2
== "Jules<1234>ffg<5678>"
>> probe rule
== [a: some [id | [skip b:]] (print copy/part a b)] Bloody hell! That should have worked! Any clues? Finally Anton, your trick always returns true, even if it didn't find the id !: line1: "Ju<li>e<><><<no-id-here>" parse line1 rule Ju<li>e<><><<no-id-here> == true So I'll have to redefine 'rule: parse line1 rule: [a: (success: false) some [id (success: true)| [skip b:]] (print copy/part a b)] if success [do something] SpliFF