erka Posted January 31, 2023 Posted January 31, 2023 Hi, I have this list of lists (will have much more sublists) : '((s -s s== -s -s== s== -s s -s s -s s -s==) (s== -s s -s s== -s s -s== s== -s s -s s -s==) (s -s== s -s s -s s== -s s -s==)) I want to append e.g. a 'q to the end of each list. Is there a function I could use? How would you do this? Quote
AM Posted January 31, 2023 Posted January 31, 2023 like that? ;; as lisp-code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setf alist '((s -s s== -s -s== s== -s s -s s -s s -s==) (s== -s s -s s== -s s -s== s== -s s -s s -s==) (s -s== s -s s -s s== -s s -s==))) (loop for i in alist collect (append i (list 'q))) => ((s -s s== -s -s== s== -s s -s s -s s -s== q) (s== -s s -s s== -s s -s== s== -s s -s s -s== q) (s -s== s -s s -s s== -s s -s== q)) ;; as lisp-function ;;;;;;;;;;;;;;;;;;;;;;;;;; (defun append-value (lists value) (loop for i in lists collect (append i (list value)))) (append-value alist 'q) => ((s -s s== -s -s== s== -s s -s s -s s -s== q) (s== -s s -s s== -s s -s== s== -s s -s s -s== q) (s -s== s -s s -s s== -s s -s== q)) JulioHerrlein and Stephane Boussuge 1 1 Quote
erka Posted January 31, 2023 Author Posted January 31, 2023 Thank you AM. That would work. I found this in the opusmodus functions. (setf alist '((s -s s== -s -s== s== -s s -s s -s s -s==) (s== -s s -s s== -s s -s== s== -s s -s s -s==) (s -s== s -s s -s s== -s s -s==))) (mapcar #'(lambda (x) (append x '(q) )) alist). => ((s -s s== -s -s== s== -s s -s s -s s -s== q) (s== -s s -s s== -s s -s== s== -s s -s s -s== q) (s -s== s -s s -s s== -s s -s== q)) Stephane Boussuge and JulioHerrlein 1 1 Quote
AM Posted January 31, 2023 Posted January 31, 2023 it's very lispian yes, it works also by (mapcar...) Quote
erka Posted February 1, 2023 Author Posted February 1, 2023 Yes, looks complicated. I used the loop advice now. Easier to understand. I was looking for a function without a loop, but then you have to use a lambda expression. To get into the loop-macro with all its possibilities is still on my list. But the collect does all I need. I get the idea that learning the loop-macro features is worth the effort. Thanks again. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.