Author Topic: What should all lisp newbies know?  (Read 8010 times)

0 Members and 1 Guest are viewing this topic.

Matt Stachoni

  • Guest
What should all lisp newbies know?
« Reply #15 on: February 10, 2004, 02:19:18 PM »
Mine would be: Make sure your code takes into account what users may do when they use your routine.

As an example, take this into account:
Code: [Select]
(setq thing
  (entget
    (car
      (entsel "\nSelect item you want to delete: ")
    )
  )
)
This will completely bomb out when the user doesn't select something - which will happen in the course of normal events.
It's better to wrap it into an (if..then..) expression:
Code: [Select]
(if (setq e (car (entsel "\nSelect the item you wish to delete:")))
  (setq e (entget e))
)

If the user doesn't select anything, (car nil) still returns nil, because nil is actually a list data type.