don't use lambda

Discussion in 'AutoCAD' started by Daniel García, Jul 16, 2003.

  1. Is some way of not using the function lambda there?

    (mapcar (function (lambda (a) (apply 'p_ess_normal a))) lis2)

    p_ess_normal is my own function

    (mapcar 'apply ........)

    Daniel Garcia
     
    Daniel García, Jul 16, 2003
    #1
  2. Daniel García

    Doug Broad Guest

    Have you tried
    (mapcar 'p_ess_normal lis2)

    ??

    Without the function or the data, that's a guess.
     
    Doug Broad, Jul 16, 2003
    #2
  3. no, lis2 is a list of list, p_ess_normal have 3 arguments and apply use the
    argument in the list

    (setq lis2 (list (list ar1 ar2 ar3) (list ar11 ar12 ar13) ......))

    apply is necesary

    Daniel Garcia
     
    Daniel García, Jul 16, 2003
    #3
  4. (apply 'mapcar
    (cons 'p_ess_normal
    (apply 'mapcar (cons 'list l))))
     
    Tony Tanzillo, Jul 16, 2003
    #4
  5. Daniel García

    Doug Broad Guest

    Tony,
    Very, very nice use of transposition!

    Daniel,
    Here are two other methods (packaged).
    Tony's method is the second one and
    probably the cleverest.

    ;;Recursive method
    (defun listproc1 (fun lst)
    (cond
    ((null lst) nil)
    ((cons (apply fun (car lst))
    (listproc fun (cdr lst))))))

    ;;Tony's transposition method
    (defun listproc2 (fun lst)
    (apply 'mapcar
    (cons fun
    (apply 'mapcar (cons 'list lst)))))

    ;;Iterative method
    (defun listproc3 (fun lst / result)
    (foreach n lst
    (setq result (cons (apply fun n) result))
    )
    (reverse result))


    ;;To run any of them: (listproc# 'yourfunction datalist)

    And if you do not need the results returned in list form:

    (foreach n datalist (apply 'yourfunction n))
     
    Doug Broad, Jul 16, 2003
    #5
  6. Thanks a lot

    --
    Daniel Garcia

     
    Daniel García, Jul 17, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.