Page 1 of 1

remove

Posted: Wed Nov 26, 2003 3:54 pm
by eddier
I'm getting a segmentation fault on

Code: Select all

(map (fn (x) (remove "\n" (read-file x))) fnames)
If I leave out the (remove I don't get the segmentation fault. Some of the files have "\r" and some don't.

Eddie

Posted: Wed Nov 26, 2003 5:12 pm
by Lutz
'remove' can only be used on lists. (read-file x) returns a string. Use 'replace' instead to remove '\r' in your files.

Of course 'remove' should not bomb on a wrong arg-type, this is fixed in development version 7.3.10 now available in the development directory:

http://newlisp.org/download/development/


Lutz

Posted: Wed Nov 26, 2003 5:48 pm
by eddier
I wonder if (replace could replace (remove ?

Eddie

Posted: Wed Nov 26, 2003 10:03 pm
by Lutz
how would you do this syntactically? nil or () as a replacement expressions wouldn't work, replace would plug in a nil or a (), while for empty strings it is fine with "". Of course one could do:

(while (set 'pos (find exp lst)) (pop lst pos))

as a replacement for 'remove'?

Or another idea would be, if the replacement expression is missing, than 'replace' works like remove? and this would also work for strings?

Lutz

Posted: Wed Nov 26, 2003 10:19 pm
by Lutz
Just checked the last suggestion: 'replace' with out replacement expression works like 'remove', in the code and it would be pretty easy to implement. After throwing the old 'replace' away, this would save a little bit of code.

Lutz