Comments on: PARSE: CHANGE added

Carl Sassenrath, CTO
REBOL Technologies
1-Oct-2009 4:31 GMT

Article #0257
Main page || Index || Prior Article [0256] || Next Article [0258] || 6 Comments || Send feedback

For A85, the CHANGE command has been added to the parse dialect.

Syntax is:

change rule |only| value

Where only is an optional word to treat the value as a single value (same as /only in the change action.)


>> parse d: "abc" [change "ab" "xy"]
>> d
== "xyc"
>> parse d: "abc" [change skip 123]
>> d
== "123bc"
>> parse d: [a b c] [change 'a [x y z]]
>> d
== [x y z b c]
>> parse d: [a b c] [change 'a only [x y z]]
>> d
== [[x y z] b c]

It is likely that bugs may exist. We will take a sweep over all parse bugs in the next release, once we've agreed on the primary design of these enhancements.

Also: you should know that this change may affect change, insert, and append for all series! datatypes. This is due to a merge between the datatype and parse modification functions.



1-Oct-2009 3:20:23
With new additions, and maybe it is only me, I have some problems with some of examples, simply put - are some operations pre, or post based? E.g. your second example:

>> parse d: "abc" [change skip 123]
>> d
== "123bc"

I expected different result at first sight. I don't know why - maybe because I am used to left-2-right REBOL level evaluation? Hence I first expected SKIP, then change to be applied.

I know I should follow definition of keywords, and it states clearly enough, that CHANGE applies against matched rule, and SKIP just matches single char, but anyway :-)

Above results are of course correct, but I just wonder, if "expectability" could cause any confusion for some users?

1-Oct-2009 4:30:53
Agreed with Pekr.

I expected "a123c" at first read ('skip, then 'change).

1-Oct-2009 5:19:32
I agree with Pekr and DideC.

Also need example for:

parse d: "abc" [change "abc" "xy"]

Essentially, if the rule is longer than the replacement.

Where is the index after this?:

parse d: "abc" [change skip 123]
1-Oct-2009 6:04:24

you might find new ?? function usefull:

>> parse d: "abc" [change skip 123 ??]
end!: "bc"
== false

... so - the index is right after the 'change applied?

1-Oct-2009 6:11:03
Pekr, I didn't notice that A85 had been released. Thanks.
1-Oct-2009 8:49:13
Guys, you didn't follow the previous note on INSERT. Did you ?

CHANGE "eat" the following rule. More obvious with that example:

>> parse s: "abc" [change "a" "123"] s
== "123bc"

CHANGE is a shortcut for REMOVE then INSERT

>> parse "abc" [change skip "123"]
same as:
>> parse "abc" [remove skip insert "123"]

Post a Comment:

You can post a comment here. Keep it on-topic.


Blog id:



 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

Updated 15-Jun-2024 - Edit - Copyright REBOL Technologies -