1
votes

I've come across the following snippet of code:

(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
  )

I'm not sure what the @ is denoting here. I've scoured the rest of the code to see if it's defined to be a function but haven't been able to find anything. My question, is "@" part of some frequently used implementation of common lisp, or is this code specific? Thanks.

Link to files: https://github.com/aimacode/aima-lisp/blob/master/agents/environments/grid-env.lisp

2

2 Answers

7
votes

The function is defined in utilities/utilities.lisp:

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

It creates a point (or a vector).

In order to find the definition, I had to clone the repository because GitHub search is practically useless when searching for code:

find -name "*.lisp" -exec grep -H @ {} \; 

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

I didn't search for defun because it could also have been a macro.

3
votes

Use a Lisp IDE

You can use the usual Lisp development environment tools to navigate in source code.

  1. start your Lisp development environment (example: GNU Emacs + SLIME).
  2. load your source code.
  3. navigate. For example in most Emacs-like editors use meta-. to locate the source for a function, variable, ... In SLIME the long command for this would be: meta-x slime-edit-definition, which then prompts for a name.

This then opens the file with the source definition and places the cursor on the relevant code.