Variable references in lisp

前端 未结 7 876
灰色年华
灰色年华 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:06

    While Common Lisp supports a functional programming style, that is not its general focus (Scheme, while not purely functional, is much closer). Common Lisp supports a completely imperative style of programming very well.

    If you find you need to write code like that, the usual solution is a macro:

    (defmacro increase-by-one (var)
      `(setf ,var (+ ,var 1)))
    

    This allows you to write code like:

    (increase-by-one foo)
    

    which will be expanded into:

    (setf foo (+ foo 1))
    

    before it is compiled.

提交回复
热议问题