Hi Volker,

good explanation!
I discover more power under the REBOL hood every time I dig in ;-)

Many thanks,
    Arie


Volker Nitsch wrote:

>Actually both methods do the same. Only Antons method inlines the "/"
>in the main rule:
>!>> compose [set word (to-lit-word first [/])]
>== [set word '/]
>while mine use a sub-rule and references it by name. so i have only to
>create that sub-rule in a special way. you could write
>  divide-word: compose [(to-lit-word first [/])]
>to make that rule, thats not the main point ;)
>sub-rules are a good trick with parse and compose, because parens have
>special meanings in both. in parse it means "process", in compose
>"expand". and if you feed compose a parse-rule with parens, it gives
>chaos.
>
>;this works:
>divide-word: to-lit-word "/"
>parse[/] [set word divide-word (?? word)]
>;this not
>parse[/] compose[set word (to-lit-word "/") (?? word)]
>;because compose replaces the (?? word) too.
>
>about: strange '/ is an invalid lit-word, but to-lit-word "/" not:
>the rebol parser has a complicated job. here it has to decide what "/"
>shall be. it could be the start of /refinement too. so it prefers to
>say "hey, invalid!". actually it is invalid by parsers rules, not the
>implementation. the parser can not sort it out. but to-lit-word does
>not go through the parser, it just takes the string and makes it a
>word. and that string is clearly defined: the stuff between "". so
>that works. only if you mold it, mold simply join ' and the word-text
>and outputs "'/", which is not loadable again. so dont save "handmade"
>words!
>
>On Apr 3, 2005 5:12 PM, Arie van Wingerden <[EMAIL PROTECTED]> wrote:
>  
>
>>Volker Nitsch wrote:
>>
>>    
>>
>>>Composing was my first thought too.
>>>But this looks cleaner (with complex rules):
>>>
>>>divide-word: to-lit-word "/"
>>>probe parse [/][ set word divide-word ]
>>>probe word
>>>
>>>On Apr 3, 2005 4:39 PM, Anton Rolls <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>      
>>>
>>>>Hi Arie,
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>>parse [/] compose [set word (to-lit-word first [/])]
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>== true
>>>>
>>>>
>>>>        
>>>>
>>>>>>word
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>== /
>>>>
>>>>Anton.
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>Hi all,
>>>>>
>>>>>while experimenting with a small dialect for calculations, I stumbled
>>>>>into a problem.
>>>>>
>>>>>I've done simple things like:
>>>>>
>>>>>          
>>>>>
>>>>>>>parse [6 * 3] [set num1 number! '* set num2 number! (print num1 *
>>>>>>>              
>>>>>>>
>>>>>num2) ]
>>>>>18
>>>>>== true
>>>>>
>>>>>However, when I try:
>>>>>
>>>>>          
>>>>>
>>>>>>>parse [6 / 3] [set num1 number! '/ set num2 number! (print num1 /
>>>>>>>              
>>>>>>>
>>>>>num2) ]
>>>>>** Syntax Error: Invalid word-lit -- '
>>>>>** Near: (line 1) parse [6 / 3] [set num1 number! '/ set num2 number!
>>>>>(print num1 / num2
>>>>>) ]
>>>>>
>>>>>REBOL complains, because (of course) '/ is not a proper lit-word.
>>>>>
>>>>>How can I still parse the / ? I already tried a charset, but I suppose
>>>>>that's only possible with string-parsing, or not?
>>>>>
>>>>>TIA
>>>>>   Arie
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>--
>>>>To unsubscribe from the list, just send an email to
>>>>lists at rebol.com with unsubscribe as the subject.
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>
>>>
>>>      
>>>
>>Hi Anton / Volker,
>>
>>many thanks for these useful solutions. In my case Volker's solution is
>>somewhat simpler to use, but I can imagine situations where Anton's
>>solution  might be more appropriate!
>>I tried both and indeed both do work fine!
>>
>>What I find strange however is that specifying '/ is an invalid lit-word
>>but to-lit-word "/" is not.
>>This looks like a contradiction to me...
>>Any ideas why this works that way (and I am glad it does ;-) ?
>>
>>Thanks again!
>>    Arie
>>
>>--
>>To unsubscribe from the list, just send an email to
>>lists at rebol.com with unsubscribe as the subject.
>>
>>
>>    
>>
>
>
>  
>
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to