Variable references in lisp

前端 未结 7 864
灰色年华
灰色年华 2020-11-29 07:04

Another newbie (Common) LISP question:

Basically in most programming languages there\'s a mean for functions to receive references to variables instead of just value

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 08:09

    Macros are probably what you want, because they don't evaluate their arguments, so if you pass a variable name, you get a variable name, not its value.

    INCF does exactly what you want, so if you google "defmacro incf" you'll find a whole bunch of definitions for this, some of which are even close to being correct. :-)

    Edit: I was suggesting INCF not as an alternative to writing your own, but because it does what you want, and is a macro so you can easily find source code for it, e.g., ABCL or CMUCL.

提交回复
热议问题