REBOL 3.0

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.)

Examples:

>> 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.

6 Comments

Comments:

-pekr-
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?

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

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

Henrik
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]
-pekr-
1-Oct-2009 6:04:24
Henrik,

you might find new ?? function usefull:

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

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

Henrik
1-Oct-2009 6:11:03
Pekr, I didn't notice that A85 had been released. Thanks.
Steeve
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.

Name:

Blog id:

R3-0257


Comment:


 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.

REBOL 3.0
Updated 19-Apr-2024 - Edit - Copyright REBOL Technologies - REBOL.net