remove

Q&A's, tips, howto's
Post Reply
eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

remove

Post 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

Lutz
Posts: 5282
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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
Last edited by Lutz on Wed Nov 26, 2003 10:04 pm, edited 1 time in total.

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

I wonder if (replace could replace (remove ?

Eddie

Lutz
Posts: 5282
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Lutz
Posts: 5282
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Post Reply