Nп/п : 53 из 93
 От   : Kaz Kylheku                         2:5075/128        31 авг 23 18:21:24
 К    : none) (albert                                         31 авг 23 21:26:02
 Тема : Re: What does (gensym) generate?
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <20230831104914.534@kylheku.com> 7d9035df
@REPLY:
9920c478
@REPLYADDR Kaz Kylheku <864-117-4973@kylheku.com>
@REPLYTO 2:5075/128 Kaz Kylheku
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <20230831104914.534@kylheku.com>
@RFC-References:

@TZUTC: -0000
@PID: slrn/pre1.0.4-9 (Linux)
@TID: FIDOGATE-5.12-ge4e8b94
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.

> 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.

> 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.

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

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.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
--- slrn/pre1.0.4-9 (Linux)
 * Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх