Jump to content

Append item to child list


Recommended Posts

amir0914

Hi all,

I want to append an item to last item in a list, like this :

lst ((x1 y1) (x2 y2) (x3 y3))

and after appending z3 to last list in lst >> lst ((x1 y1) (x2 y2) (x3 y3 z3))

 

Can someone tell me how I can perform it?

Link to post
Share on other sites
rlx
(subst (append (last lst) (list 'z3)) (last lst) lst)
(reverse (cons (append (car (reverse lst)) (list 'z3)) (cdr (reverse lst))))

 

Edited by rlx
  • Like 1
Link to post
Share on other sites
Lee Mac

One more for fun -

(reverse (cons (reverse (cons 'z3 (reverse (last lst)))) (cdr (reverse lst))))

 

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...