Page 1 of 1

functional programming

Posted: Wed Oct 15, 2003 8:22 pm
by 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

Code: Select all

(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

Posted: Thu Oct 16, 2003 2:57 pm
by Lutz
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

Posted: Thu Oct 16, 2003 3:04 pm
by HPW
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.

Posted: Fri Oct 17, 2003 7:59 pm
by eddier
Thanks Lutz for the changes in 7.2.4. Now I can kill the library with functional versions of replace, remove, etc...

Eddie

Posted: Mon Oct 20, 2003 12:30 am
by Lutz
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