@MSGID:
0085e4af @REPLY: <20230831104914.534@kylheku.com> 7d9035df @REPLYADDR none) (albert @REPLYTO 2:5075/128 none) (albert @CHRS: CP866 2 @RFC: 1 0 @RFC-References: <20230831104914.534@kylheku.com> @RFC-Message-ID: @TZUTC: 0200 @TID: FIDOGATE-5.12-ge4e8b94
In article <20230831104914.534@kylheku.com>,
Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>On 2023-08-31, albert@cherry.(none) (albert) wrote:
>> The explanations about the usage of gensym are clear,
>> how your are supposed to used them.
>> The theoretical background however is far from it.
>>
>> (let* (aaa (gensym)) .. aaa .. )
>>
>> In the context `` .. aaa .. `` `aaa is obviously a symbol.
>> The interesting question is what value is aaa coupled to due to
>> the environment (aaa (gensym))?
>
>gensym is an ordinary function which returns an object.
>That object is a symbol.
>
>If we replace it with (aaa (list 1 2 3)), then aaa is bound
>to list of three elements.
>
>The object returned by gensym is always a newly created symbol,
>different from any other symbol in the system that has hitherto existed.
>
>In Common Lisp, gensym returns an uninterned symbol: a symbol which
>is not registered in a package. (There are some subtle details to it,
>but let that suffice.) Common Lisp prints such symbols with a #:
>(hash colon) prefix. E.g. (gensym "ABC-") -> #:ABC-0013 .
>The Common Lisp gensym maintains an incrementing counter which it uses
>to generate new names, but those names are just for human readability,
>not the basis for the uniquenes..
>
>Each time the reader encounters the #: syntax, it creates a new,
>uninterned symbol so that (eq `#:abc `#:abc) will be false.
>Those are two different symbols, which have the same name.
>
>For interned symbols, that is impossible: only one symbol can
>exist in a package under a given name: there can at most be one cl:list
>or abc:foo or whatever.
That is all trivial to implement.
>
>> However subsequently you see
>> (let* (aaa (rest whatever)) ... )
>> What is disturbing to me is that let* only allows symbols into the
>> position of aaa and normally the coupling of aaa hides previous usage.
>
>It`s a variable binding construct, so it only allows variable names,
>which are symbols.
Huh?
>
>> I have the following lisp type of objects:
>> symbols lists numbers strings arrays hashes normal-function
>> special-functions booleans
>> and more MAL oddballs:
>> nil key atom
>>
>> Nothing seems an appropriate type for `aaa.
>
>The obect aaa itself is a symbol. The token aaa appears in your code.
>The Lisp reader scans that token, recognizes it as having the
>shape of a symbol, and so it interns it: it produces either the
>existing symbol that exists under that name, or else produces a new
>one and registers it under that name. (If it didn`t register it,
>the symbol would be uninterned, like the ones from gensym.)
>
>I`m guessing that since you`ve gone this far in MAL, you must
>have that working.
Right you are
>
>> (let* (condvar (gensym))
>> `(let* (~condvar ~(first xs))
>> (if ~condvar ~condvar (or ~@(rest xs)))))))))
>
>So here condvar is a generated, unique symbol.
>
>It is interpolated into the backquote template.
>
>~convar says, insert the value of condvar here. The value is
>a symbol, which is what we want there.
Can we conclude that the only time to worry is inside
quasiquote? That helps a lot. There is a moment in time
where we expand, and the
>
>The macro is generating code in which there is a local variable boudd
>using let*, and that variable`s name is machine generated.
>
>This the same as what you see in any compiler: machine generated
>temporaries, jump labels and so on.