Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: CDR and CADR in this lisp

  1. #1
    Member
    Join Date
    2011-10
    Posts
    40
    Login to Give a bone
    0

    Default CDR and CADR in this lisp

    This is lisp programme to make selected object 's layer as current layer.

    i used 1st cadr function (in place of CDR). it results some error. And then i used CDR . it works fine. can u tell me what is excat function of this two function. i supposed that cadr will be work well. please explain it


    (DEFUN C:ES()
    (SETQ A(CAR(ENTSEL "\Select Entity To current Layer..")))
    (setq b(cdr (assoc 8(entget a))))
    (command "-layer" "s" b ""))

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp

    cdr - removes first element of a list and returns that list without first element

    cadr = (car (cdr)) - removes first element of a list takes first element of resultant list (previously removed first element), so it basically means that cadr takes second element of a list and returns that element, because :

    car - takes first element from a list and returns that first element

    M.R.

  3. #3
    Member
    Join Date
    2011-10
    Posts
    40
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp

    so basically it wouldn't be error if cadrs are being used in this line (setq b(cdr (assoc 8(entget a)))) what u say ?



    Quote Originally Posted by marko_ribar View Post
    cdr - removes first element of a list and returns that list without first element

    cadr = (car (cdr)) - removes first element of a list takes first element of resultant list (previously removed first element), so it basically means that cadr takes second element of a list and returns that element, because :

    car - takes first element from a list and returns that first element

    M.R.
    Last edited by sanrajbhar677632; 2011-10-20 at 12:22 PM.

  4. #4
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp


  5. #5
    Member
    Join Date
    2011-10
    Posts
    40
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp

    Frnds, Please if i am some silly. dont mind. iam just learning it.

    the below code is work well. can i know if entity is not get selected it should prompt No entity slected(without ending of programe).



    Quote Originally Posted by sanrajbhar677632 View Post
    This is lisp programme to make selected object 's layer as current layer.

    i used 1st cadr function (in place of CDR). it results some error. And then i used CDR . it works fine. can u tell me what is excat function of this two function. i supposed that cadr will be work well. please explain it


    (DEFUN C:ES()
    (SETQ A(CAR(ENTSEL "\Select Entity To current Layer..")))
    (setq b(cdr (assoc 8(entget a))))
    (command "-layer" "s" b ""))

  6. #6
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp

    The simplest solution could be:

    Code:
    (while (null (setq ent (car (entsel))))
        (princ "\nNothing Selected.")
    )

  7. #7
    Member
    Join Date
    2011-10
    Posts
    40
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp

    great ! how to using "IF" Function


    Quote Originally Posted by Lee Mac View Post
    The simplest solution could be:

    Code:
    (while (null (setq ent (car (entsel))))
        (princ "\nNothing Selected.")
    )

  8. #8
    Member
    Join Date
    2011-10
    Posts
    40
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp

    great ! how to using "IF" Function?


    Quote Originally Posted by Lee Mac View Post
    The simplest solution could be:

    Code:
    (while (null (setq ent (car (entsel))))
        (princ "\nNothing Selected.")
    )

  9. #9
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp

    Code:
    (if (setq ent (car (entsel)))
        (expression_if_true)
        (princ "\nNothing Selected.")
    )

  10. #10
    Member
    Join Date
    2011-10
    Posts
    40
    Login to Give a bone
    0

    Default Re: CDR and CADR in this lisp

    It doesn't seems to works ?



    Quote Originally Posted by Lee Mac View Post
    Code:
    (if (setq ent (car (entsel)))
        (expression_if_true)
        (princ "\nNothing Selected.")
    )

Page 1 of 2 12 LastLast

Similar Threads

  1. Help with car and cadr points
    By cmorris283 in forum AutoLISP
    Replies: 4
    Last Post: 2014-02-04, 12:45 PM
  2. Replies: 13
    Last Post: 2014-01-20, 06:14 PM
  3. Replies: 3
    Last Post: 2012-05-07, 08:16 PM
  4. Replies: 9
    Last Post: 2012-01-21, 07:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •