What the meaning (setq table_list '())

Discussion in 'AutoCAD' started by Adesu, Mar 2, 2005.

  1. Adesu

    Adesu Guest

    I've got this file from ai_utils.lsp (support folder),I don't know what
    purpose and meaning the "(setq table_list '())",if we check only result
    "nil"

    (defun ai_table (table_name bit / tbldata table_list just_name)
    (setq tbldata nil)
    (setq table_list '())
    (setq table_name (xstrcase table_name))
    (while (setq tbldata (tblnext table_name (not tbldata)))
    (setq just_name (cdr (assoc 2 tbldata)))
    ;-------------------------------------------------------------snip----------
    -------
     
    Adesu, Mar 2, 2005
    #1
  2. (setq tbldata nil)
    Those lines are doing nothing there... normally they can be used at debugging phase...
     
    Luis Esquivel, Mar 2, 2005
    #2
  3. The expressions '() and nil are the same.

    You can use them interchangeably:

    (setq table_list nil)
    (setq table_list '())

    Why someone at Autodesk did that, I don't know.
     
    Tony Tanzillo, Mar 2, 2005
    #3
  4. Adesu

    Adesu Guest

    Hi Tony and Luis,thanks for your info

     
    Adesu, Mar 2, 2005
    #4
  5. For this one you can't blame Autodesk, the guilty party is probably John
    McCarthy or some other early Lisp programmer: this is standard in almost
    every Lisp implementation (except Scheme). Actually it is a quite neat
    idea, as you'll notice if you ever try to program in Scheme.

    This gives you the possibility to write something like

    (setq result (some-function-producing-lists))
    ....
    (if result (do-something)
    (do-something-else))


    instead of


    (if (not (null result)) (do-something)
    (do-something-else))






    A few more words on this:
    http://www.delorie.com/gnu/docs/elisp-manual-21/elisp_6.html
    http://oopweb.com/LISP/Documents/cltl/VolumeFrames.html?/LISP/Documents/cltl/Volume/clm/node9.html

    --
     
    Martti Halminen, Mar 2, 2005
    #5
  6. I would like to hear more about why "Scheme" criteria is to neat?... I went
    and read the two url-links and do not see any benefit.... :-(

    can you elaborate more on this?

    also to me I never have seen the use of (if (not (null result)) .... can you
    post some code using this approach or style?

    normally is use:

    (if result (this) (that))

    or'

    (if (not this) (setq this "default"))
     
    Luis Esquivel, Mar 2, 2005
    #6
  7. Adesu

    MP Guest

    I thought he was implying that the lack of the above mentioned
    implementation was a negative aspect in Scheme
    (whatever that is)
    I thought he meant you'd only have to do this in a language like scheme that
    lacked the nil / '() equivalence.
    I thought he was indicating that this *is* possible due to the equivalence
    of nil and '() in most lisp implementations. (including our favorite
    autolisp)
    :)
    cheers
    Mark
     
    MP, Mar 2, 2005
    #7
  8. But if you are talking about AutoLISP, you've always been able to write
    expressions as

    (if result (do-something)
    (do-something-else)
    )

    No matter what the value of result is.

    Matt

     
    Matt Stachoni, Mar 2, 2005
    #8
  9. I wasn't blaming Autodesk for the fact that '() and nil
    are equivalent, but was commenting on the use of both
    (however, in retrospect it seems the programmer was
    using '() to emphasize that the variable was a list, which
    as your references point out, is fine).

    As I've been led to understand it, the history behind NULL
    is that in some early implementations of LISP, NIL and the
    empty list were not equivalent, and so NULL was needed
    to test a list for emptyness, and NOT was used for logical
    operations.

    That eventually changed, and NIL became the same as an
    empty LIST. When that happened, NULL was changed to
    be functionally equivalent, if not identical to NOT.
     
    Tony Tanzillo, Mar 2, 2005
    #9
  10. In Scheme the only truth values are #t and #f, an empty list does not
    have any special significance there. Like most Common Lisp programmers,
    I consider this a bad design decision: the lisp-style nil as false,
    everything else is true is far more convenient in my opinion.

    As this is quite unnecessary when we have the nil-false equivalency,
    this is not very common. Occasionally this gets used for emphasis.

    You can get more examples of this style in any java program, where empty
    collections are not handled as gracefully as in lisp. They are not good
    examples ... :-/

    --
     
    Martti Halminen, Mar 3, 2005
    #10
  11. McCarthy's original 1960 paper about Lisp only had T and F as truth
    values. In the LISP 1.5 manual (1966) there are *T* and F, but NIL is
    already also recognized as boolean false.

    In Common Lisp NULL and NOT are functionally equivalent; in LispWorks
    they actually both produce exactly the same machine code.

    So, the only difference is style: using NOT tells the human reading the
    program that you are interested in logical negation, NULL implies you
    are checking whether the list is empty. (Assuming you use this style...)


    --
     
    Martti Halminen, Mar 3, 2005
    #11
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.