Author Topic: (discussion) Costruct procedures with Lambda  (Read 10328 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (discussion) Costruct procedures with Lambda
« Reply #30 on: March 03, 2006, 07:41:32 AM »
Now that is lambda. Let me take some time to digest it.

Welcome to the swamp ElpanovEvgeniy.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (discussion) Costruct procedures with Lambda
« Reply #31 on: March 03, 2006, 07:50:23 AM »
Very elegant contributions ElpanovEvgeniy, welcome to the swamp.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (discussion) Costruct procedures with Lambda
« Reply #32 on: March 03, 2006, 08:13:17 AM »
Thanks everything, for kind words!
 :-)

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
Re: (discussion) Costruct procedures with Lambda
« Reply #33 on: March 03, 2006, 09:47:07 AM »
W H A T   I S   T H A T?!
*smile* Thank you Evgeniy. Welcome to theSwamp.

This all came about when I started to think about a simple mapcar-lambda statment so then I turned to my favorite book S.I.C.P. for answers. But then I got really confused and frustrated... This is what im reading. [ LINK ]

But some of the things i was looking to answer were.
*If a lambda is an unnamed definition and typicaly used at the point of the use.*
o  when used in a looping statment is that lambda redefined each time a new item is picked off.
o  By Using lambda vs a solid name, would your program slow down and become " bloated "?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (discussion) Costruct procedures with Lambda
« Reply #34 on: March 04, 2006, 05:42:12 PM »
>Se7en

I compared time of performance
setq + while >> time >> mapcar + lambda
PS.But now, I would write not so...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (discussion) Costruct procedures with Lambda
« Reply #35 on: March 05, 2006, 04:44:27 PM »
But some of the things i was looking to answer were.
*If a lambda is an unnamed definition and typicaly used at the point of the use.*
o  when used in a looping statment is that lambda redefined each time a new item is picked off.
o  By Using lambda vs a solid name, would your program slow down and become " bloated "?
Then review here. I am assured, you will understand sense.
Code: [Select]
(defun multi-subst-fun (lst-i)
  (eval
    (list
      'defun
      'multi-subst
      '(lst)
      (list
        'mapcar
        (list 'function
              (list
                'lambda
                '(a)
                (cons
                  'cond
                  (reverse
                    (cons
                      '(t a)
                      (mapcar
                        '(lambda (a)
                           (list
                             (list
                               'equal
                               (car a)
                               'a
                             ) ;_  list
                             (cadr a)
                           ) ;_  list
                         ) ;_  lambda
                        lst-i
                      ) ;_  mapcar
                    ) ;_  cons
                  ) ;_  reverse
                ) ;_  cons
              ) ;_  list
        ) ;_  list
        'lst
      ) ;_  list
    ) ;_  list
  ) ;_  eval
) ;_  defun
;; do the test...
Code: [Select]
(multi-subst-fun '((1 "a") (3 "b")))

(multi-subst '(1 2 3 4 5))
(multi-subst '(1 6 4 3 7))
I have answered your question?

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (discussion) Costruct procedures with Lambda
« Reply #36 on: May 18, 2006, 06:26:08 AM »
Code: [Select]
(setq lst '(1 2 3 4 5 6 7 8 9 10 11 12))
  ; Variant through defun
(defun lst-3d-pt (lst)
  (if lst
    (cons (list (car lst) (cadr lst) (caddr lst)) (lst-3d-pt (cdddr lst)))
  ) ; _ if
) ; _ defun

(setq 3d-lst (lst-3d-pt lst))
; 3d-lst = '((1 2 3) (4 5 6) (7 8 9) (10 11 12))


  ; Variant through lambda
(setq f      (lambda (x)
               (if x
                 (cons (list (car x) (cadr x) (caddr x)) (f (cdddr x)))
               ) ; _ if
             ) ; _ lambda
      3d-lst (f lst)
) ; _ setq
; 3d-lst = '((1 2 3) (4 5 6) (7 8 9) (10 11 12))

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (discussion) Costruct procedures with Lambda
« Reply #37 on: October 08, 2006, 11:05:29 AM »
I have found very interesting site on a theme 'Lambda...
http://autolisp.mapcar.net/lambda.html



<edit: repair link>
Here it is translated into English. No Word wrap! CAB
http://tinyurl.com/lq7ct
« Last Edit: October 08, 2006, 11:40:49 AM by CAB »