【问题标题】:What does @ denote in Common Lisp?在 Common Lisp 中 @ 表示什么?
【发布时间】:2018-03-03 08:23:32
【问题描述】:

我遇到了以下sn-p的代码:

(defstructure object
  "An object is anything that occupies space.  Some objects are 'alive'."
  (name "?")            ; Used to print the object on the map
  (alive? nil)                  ; Is the object alive?
  (loc (@ 1 1))         ; The square that the object is in
  (bump nil)            ; Has the object bumped into something?
  (size 0.5)            ; Size of object as proportion of loc
  (color 'black)        ; Some objects have a color
  (shape 'rectangle)        ; Some objects have a shape
  (sound nil)           ; Some objects create a sound
  (contents '())        ; Some objects contain others
  (max-contents 0.4)            ; How much (total size) can fit inside?
  (container nil)       ; Some objects are contained by another
  (heading (@ 1 0))     ; Direction object is facing as unit vector
  )

我不确定这里的@ 表示什么。我已经搜索了其余的代码,看看它是否被定义为一个函数,但还没有找到任何东西。我的问题是,“@”是一些常用 lisp 的常用实现的一部分,还是这段代码是特定的?谢谢。

文件链接: https://github.com/aimacode/aima-lisp/blob/master/agents/environments/grid-env.lisp

【问题讨论】:

    标签: common-lisp


    【解决方案1】:

    函数定义在utilities/utilities.lisp:

    (defun @ (x y) "Create a 2-D point" (make-xy :x x :y y))
    

    它创建一个点(或向量)。

    为了找到定义,我不得不克隆存储库,因为在搜索代码时,GitHub 搜索实际上是无用的:

    find -name "*.lisp" -exec grep -H @ {} \; 
    
    ...
    ./utilities/utilities.lisp:(defun @ (x y) "Create a 2-D point" (make-xy :x x :y y))
    ...
    

    我没有搜索defun,因为它也可能是一个宏。

    【讨论】:

    • 谢谢伙计。是的,刚刚意识到他们不喜欢特殊角色
    【解决方案2】:

    使用 Lisp IDE

    您可以使用常用的 Lisp 开发环境工具在源代码中导航。

    1. 启动您的 Lisp 开发环境(例如:GNU Emacs + SLIME)。
    2. 加载您的源代码。
    3. 导航。例如,在大多数类似 Emacs 的编辑器中,使用 meta-. 来定位函数、变量等的源代码......在 SLIME 中,用于此的长命令将是:编辑定义,然后提示输入名称。

    然后打开包含源定义的文件并将光标放在相关代码上。

    【讨论】:

      猜你喜欢
      • 2013-03-24
      • 2015-07-03
      • 2019-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-20
      • 2011-03-31
      • 1970-01-01
      相关资源
      最近更新 更多