Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do keywords work in Common Lisp?
    primarykey
    data
    text
    <p>The question is not about <em>using</em> keywords, but actually about keyword <em>implementation</em>. For example, when I create some function with keyword parameters and make a call:</p> <pre><code>(defun fun (&amp;key key-param) (print key-param)) =&gt; FUN (find-symbol "KEY-PARAM" 'keyword) =&gt; NIL, NIL ;;keyword is not still registered (fun :key-param 1) =&gt; 1 (find-symbol "KEY-PARAM" 'keyword) =&gt; :KEY-PARAM, :EXTERNAL </code></pre> <p>How a keyword is used to pass an argument? Keywords are symbols whos values are themselves, so how a corresponding parameter can be bound using a keyword?</p> <p>Another question about keywords — keywords are used to define packages. We can define a package named with already existing keyword:</p> <pre><code>(defpackage :KEY-PARAM) =&gt; #&lt;The KEY-PARAMETER package, 0/16 ... (in-package :KEY-PARAM) =&gt; #&lt;The KEY-PARAMETER package, 0/16 ... (defun fun (&amp;key key-param) (print key-param)) =&gt; FUN (fun :KEY-PARAM 1) =&gt; 1 </code></pre> <p>How does system distinguish the usage of <code>:KEY-PARAM</code> between package name and function parameter name? Also we can make something more complicated, if we define function <code>KEY-PARAM</code> and export it (actually not function, but name):</p> <pre><code>(in-package :KEY-PARAM) (defun KEY-PARAM (&amp;key KEY-PARAM) KEY-PARAM) =&gt; KEY-PARAM (defpackage :KEY-PARAM (:export :KEY-PARAM)) ;;exporting function KEY-PARAM, :KEY-PARAM keyword is used for it (in-package :CL-USER) =&gt; #&lt;The COMMON-LISP-USER package, ... (KEY-PARAM:KEY-PARAM :KEY-PARAM 1) =&gt; 1 ;;calling a function KEY-PARAM from :KEY-PARAM package with :KEY-PARAM parameter... </code></pre> <p>The question is the same, how Common Lisp does distinguish the usage of keyword <code>:KEY-PARAM</code> here?</p> <p>If there is some manual about keywords in Common Lisp with explanation of their mechanics, I would be grateful if you posted a link here, because I could find just some short articles only about usage of the keywords.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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