Author Topic: map the mapcar  (Read 675 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 11732
  • AutoCAD 2015 Windows 7 London, England
Re: map the mapcar
« Reply #15 on: April 14, 2017, 10:31:47 am »
Thanks Grrr.

Note that: (mapncar 0 (lambda (x) (reverse x)) Lst) can become: (mapncar 0 reverse lst)

Grrr1337

  • Bull Frog
  • Posts: 338
Re: map the mapcar
« Reply #16 on: April 14, 2017, 11:04:04 am »

Note that: (mapncar 0 (lambda (x) (reverse x)) Lst) can become: (mapncar 0 reverse lst)

Ah, ofcourse! Well.. the point is to have fun manipulating assoc/nested assoc lists. :)

gile

  • Water Moccasin
  • Posts: 2080
  • Marseille, France
Re: map the mapcar
« Reply #17 on: April 14, 2017, 11:04:17 am »
Thanks Grrr.

Note that: (mapncar 0 (lambda (x) (reverse x)) Lst) can become: (mapncar 0 reverse lst)

Or simply: (mapcar 'reverse lst)

Lee, is there any reason you prefer use non-quoted function as argument in higher order functions? What's wrong with built in AutoLISP functions standard quoted ones?
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 11732
  • AutoCAD 2015 Windows 7 London, England
Re: map the mapcar
« Reply #18 on: April 14, 2017, 11:12:36 am »
Lee, is there any reason you prefer use non-quoted function as argument in higher order functions? What's wrong with built in AutoLISP functions standard quoted ones?

No particular reason in this case, I simply overlooked it - but I agree that the function may be better written:
Code - Auto/Visual Lisp: [Select]
  1. (defun mapncar ( n f l )
  2.    (if (< 0 n)
  3.        (mapcar '(lambda ( x ) (mapncar (1- n) f x)) l)
  4.        (mapcar f l)
  5.    )
  6. )

Such that a quoted function may be supplied, consistent with standard AutoLISP functions.

Usually it becomes necessary to supply an unquoted function to avoid the use of eval or apply within the subfunction.