Author Topic: Mapcar and lambda manipulation  (Read 874 times)

0 Members and 1 Guest are viewing this topic.

Jim2018

  • Mosquito
  • Posts: 16
Mapcar and lambda manipulation
« on: February 14, 2022, 06:01:30 PM »
I want to add, using mapcar and lambda, to the elements of a list ((X1 Y1) (X2 Y2) .... (Xn Yn)) a string type element that will count the members of the list, starting from (one) 1 and will have the form (("1" X1 Y1) ("2" X2 Y2) .... ("n" Xn Yn)).
The only I have managed is to create a list (" " X1 Y1) (" " X2 Y2) .... (" " Xn Yn)) with the following order  (mapcar '(lambda (x) (cons " ")) e_list)
Any help accepted

baitang36

  • Bull Frog
  • Posts: 213
Re: Mapcar and lambda manipulation
« Reply #1 on: February 14, 2022, 08:28:51 PM »
Code - Auto/Visual Lisp: [Select]
  1. (setq e_list '( (1 1) (2 2) (3 3) (4 4)))
  2. (setq y 0)
  3. (mapcar '(lambda (x)
  4.            (setq y (+ 1 y ) )
  5.            (cons   (itoa y) x)
  6.          )
  7.         e_list
  8. )

it return (("1" 1 1) ("2" 2 2) ("3" 3 3) ("4" 4 4))

Jim2018

  • Mosquito
  • Posts: 16
Re: Mapcar and lambda manipulation
« Reply #2 on: February 17, 2022, 05:14:24 AM »
Thank you!!!