Author Topic: map the mapcar  (Read 7366 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12905
  • 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

  • Swamp Rat
  • Posts: 812
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. :)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

gile

  • Gator
  • Posts: 2507
  • 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: 12905
  • 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.