functional programming

Started by eddier, October 15, 2003, 01:22:42 PM

Previous topic - Next topic

eddier

It would be nice if the procedures push, remove, replace, etc, were functions that is,  returned their  results like sort and returned the info they now return through their name as a system variable.



Example

(set 'aList '(a b c d e a b c d))
(replace 'b aList 'B)              => (a B c d e a B c d)
$$ => 2


Making everything a function would cut down on those (begin thingys. And allow functional composition of  push, remove, replace, etc, with other functions.



Eddie

Lutz

#1
When those functions 'replace', 'replace-nth' and 'replace-assoc' where written I had in mind to save memory when using these on big in memory datatbases.



'sort' and 'reverse' then where written not this way and return the result working in a functional way, which of course was inconsistent with the replace family of functions.



Perhaps the best would be having them all return their result and making them non-destructive, so only the functions having to change the contents of a symbol would be destructive.



The only problem I have, is, that it would break a lot of code out there. But it clearly would be more consistent and save some sequential no-functional code.



I personally would agree to this change making them all non-destrutive with functional returns, but I don't know how others (beside you) think about it?



Perhaps announcing it a couple versions early and then doing it in 8.0?



What does everybody else think?



Lutz

HPW

#2
For me it would be not a problem, because I just start to port larger

sources to newLisp. I only had to know early where it goes. Of cource

consistents sounds always good.



But others will have more to change.



Just my 2 cents.
Hans-Peter

eddier

#3
Thanks Lutz for the changes in 7.2.4.  Now I can kill the library with functional versions of replace, remove, etc...



Eddie

Lutz

#4
thanks for making the suggestions to change those functions in the first place ;) .  I left push the way it is, to have at least one pair of destructive primitives (push, pop) to modify big in-memory lists without allocating memory for a copy of the list.



Also when push is used without the offset parameter, you can just use 'cons' which does returns the modified list.



Lutz