4 ms·
I have a feeling you don't have much CL experience... There really aren't very many CL destructive (mutating) list functions, and I personally almost never use
by Hexstream 18y ago
I have a feeling you don't have much CL experience...
There really aren't very many CL destructive (mutating) list functions, and I personally almost never use them except on fresh lists (like for example when I nreverse a list I just created with successive pushes) and I'm pretty sure it's standard practice.
Let's see what destructive list functions I can find in CL (ref: http://www.lispworks.com/documentation/HyperSpec/Body/c_conses.htm http://www.lispworks.com/documentation/HyperSpec/Body/c_cons...)
rplaca, rplacd, nsublis, nsubst*, nconc, nreconc, nbutlast, mapcan, mapcon, nintersection, nset-difference, nset-exclusive-or
I took some liberties but that's about 12/58 = 20% destructive functions (push, pop, pushnew are usually used on variables, not list structure). And good style dictates to use them very sparsely... Also, (loop for x in some-list sum (* 2 x)) is pretty functional, you're just mutating x locally but who cares, this is exactly like saying (apply #'+ (mapcar (lambda (x) (* 2 x)))) which is obviously functional.
- Hexstream 18y agoI knew something wasn't quite right. I forgot the sequence functions. So add this to the list: fill, map-into, nreverse, replace, nsubstitute, merge, delete, delete-duplicates So about 20/85 = 23,5%
- jrockway 18y agoPoint conceded. The post I replied to says "CL discourages mutation" which is not true. I said "nearly all sequence functions are destructive", which is also not true. Upon further reflection, I think we can say CL doesn't really care if you mutate or not. There's more than one way to do it :)
- Hexstream 18y agoCL does discourage mutation... With all the structure sharing going on in CL programs you can't afford mutating things thoughtlessly.
- jrockway 18y agoBut OTOH, if you are careful about mutating when possible, your program will run faster. Not the most important thing in the world, I agree, but it is a "reward" for mutating things.
- plinkplonk 18y agoUpvoted for "Point conceded.". We don't see enough of this.
- anamax 18y ago> I said "nearly all sequence functions are destructive", Actually, you said "nearly all of the standard list functions". You do know that CL has sequences that are not lists, right?