functional programming

For the Compleat Fan
Locked
eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

functional programming

Post 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

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

Post 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

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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.
Hans-Peter

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

Post 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

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

Post 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

Locked