Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's not clear exactly what you're looking for. The default case for structures is a record type with a fixed number of slots, each of which has a name, and is accessible through a function generated by the <code>defstruct</code> macro. E.g., once you've done</p> <pre><code>(defstruct node label) </code></pre> <p>you can access a <code>node</code>'s label with <code>node-label</code> and get fast lookup time (since it's typically just an index into a memory chunk). Now, as you're doing, you can opt to use lists as the implementation of structures, in which case <code>node-label</code> is just an alias for <code>car</code> or <code>first</code>.</p> <pre><code>(defstruct (node (:type list)) label) CL-USER&gt; (make-node :label 'some-label) (SOME-LABEL) CL-USER&gt; (node-label (make-node :label 'some-label)) SOME-LABEL CL-USER&gt; (first (make-node :label 'some-label)) SOME-LABEL CL-USER&gt; (car (make-node :label 'some-label)) </code></pre> <p>If you're looking for arbitrary list-based key value pairs, you probably want a <a href="http://clhs.lisp.se/Body/26_glo_p.htm#property_list">property list</a>, for which Common Lisp contains some convenience functions. </p> <p>If you want to have a structure that also contains a property list, you could add a special constructor populate that list. For instance, </p> <pre><code>(defstruct (node (:type list) (:constructor make-node (label &amp;rest plist))) label plist) CL-USER&gt; (make-node 'some-label :one 1 :two 2) (SOME-LABEL (:ONE 1 :TWO 2)) CL-USER&gt; (node-plist (make-node 'some-label :one 1 :two 2)) (:ONE 1 :TWO 2) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload