replace

View: New views
6 Messages — Rating Filter:   Alert me  

replace

by Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

why do

> replace(({1,2,3}),2,17);        
(6) Result: ({ /* 3 elements */
                1,
                17,
                3
            })

work, while

> replace(({1,2,3}),({2}),({17}));
(5) Result: ({ /* 3 elements */
                1,
                2,
                3
            })

does nothing?

replace

by Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Because ({1,2,3}) does not contain an element with the value ({2})?
OTOH, this doesn't seem to work either:

> replace(({1,({2}),3}),({2}),({17}));
(1) Result: ({ /* 3 elements */
                1,
                ({ /* 1 element */
                    2
                }),
                3
            })

replace

by Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, it does.

> array a=({2});
> replace(({1,a,3}),a,({17}));
(1) Result: ({ /* 3 elements */
                1,
                ({ /* 1 element */
                    17
                }),
                3
            })

replace

by Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ah, of course.  Well, that should answer Mirar's question then.

replace

by Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ah, I guess multi-replace is only for strings. I tried using just two
arguments with the second a mapping first, but that wasn't accepted
either.

Re: replace

by Martin Baehr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hmm, i can see how

  replace(({ 1,2,3, }), ({ 2 }), ({ 17 }));

is not clear whether it is to replace 2 or ({2}), but

  replace(({ 1,2,3, }), ([ 2:17 ]));

should be unmistakeable.
currently it leads to an error, but i think it can be made to work.

greetings, martin.