vseloved / rutils

Radical Utilities for Common Lisp
Other
250 stars 37 forks source link

Push an element to the end of a list? #23

Closed mmontone closed 9 years ago

mmontone commented 9 years ago

Is there some utility to push some element to the end of a list? Makes sense to implement one?

(let ((l (list :foo))) (push-end :bar l) l) => (:foo :bar)

push-end, push-last, I don't know how to call it.

mmontone commented 9 years ago

The equivalent of:

(let ((l (list :foo))) (rutils.list:appendf l (list :bar)))

vseloved commented 9 years ago

Hmm, it's an interesting question. Maybe, implementing something so inefficient and making it seem easy is not a good idea. Do you have a lot of use cases for it?

mmontone commented 9 years ago

Well..it appears here and there for me. I often implement it manually, like above, having to append lists. As for the performance, I'm not sure what to do about it. Add a warning in the documentation? It may be that it is not a good idea to include something like this, I don't know, but I think it is fairly common in other languages, isn't it? Append an element to a list destructively.

vseloved commented 9 years ago

I'd say that it's common in languages that have lists implemented on top of arrays (like Python). I guess, adding a warning to the docs should be enough. Care to create a pull request with the utility and tests? (Btw, I'd call it not push-end but something like tack or attach. What do you think?)

vseloved commented 9 years ago

Actually, I've just recalled that you can use setf last-elt for this. It's much neater, isn't it?

mmontone commented 9 years ago

El 16 de julio de 2015 4:03:15 GMT-03:00, Vsevolod Dyomkin notifications@github.com escribió:

Actually, I've just recalled that you can use setf last-elt for this. It's much neater, isn't it?

Ah. That's a good one!


Reply to this email directly or view it on GitHub: https://github.com/vseloved/rutils/issues/23#issuecomment-121853164