Nп/п : 57 из 93
 От   : none) (albert                       2:5075/128        01 сен 23 14:23:21
 К    : Kaz Kylheku                                           01 сен 23 15:25:02
 Тема : Re: What does (gensym) generate?
----------------------------------------------------------------------------------
                                                                                 
@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.

The big question how to parse
    (let (aaa  )  ...
In the abstract structure tree `let and `aaa are symbols
that are manipulated during evaluation.
The spec`s of let  is that aaa is a symbol that is bound to object.
This cannot be the whole story. For instance there is no notice
to evaluate aaa , the previous binding is lost.
That are the spec`s of `let , or so I thought.
Comes gensym . If I previously encountered `` (aaa (gensym)) ``
everything changes. But how can I even know that the previous
binding was this weird contraption?

I have 256 Gbyte RAM and MAL is a toy implementation, so bear with me:
each object has 7 64 bit fields.
All objects are uniform and have a tag giving its type:
pointer to code, pointer to data, a flag field (containing tags),
a link field, a name field, a source field (not used) and
one spare.

It is related to the following implementation choice I made.
All objects have a place to set a name.
All object have some data and possibly no name (e.g. numbers, lists
functions, strings)
Symbols have a name and all other fields are free.
Binding a symbol : fill the name of the symbol in the object
and possibly link it into an environment (linkfield is the hook for that).
Sometime we have to clone the whole object, if it previously had a name
and were linked to some environment.
For example an anonymous lambda looks like this:
code pointer : forth interpreter
data pointer : forth code to be interpreted
flag : contains either #func or #special or-ed with possibly Forty flags.
link , name : empty.

The contradiction caused by (gensym) is that you have symbols with
two names, where the only property of a symbol is that it has
a name that identifies itself. Or so I thought.

>
>--
>TXR Programming Language: http://nongnu.org/txr

Groetjes Albert
-- 
Don`t praise the day before the evening. One swallow doesn`t make spring.
You must not say "hey" before you have crossed the bridge. Don`t sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning.            - the Wise from Antrim -
--- trn 4.0-test77 (Sep 1, 2010)
 * Origin: KPN B.V. (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    
                                                                                
В этой области больше нет сообщений.

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