Nп/п : 17 из 93
 От   : none) (albert                       2:5075/128        08 июл 23 10:05:06
 К    : Kaz Kylheku                                           08 июл 23 11:09:17
 Тема : Re: IMMEDIATE and def_macro
----------------------------------------------------------------------------------
                                                                                 
@MSGID:
cd33c0fc
@REPLY: <20230707102938.23@kylheku.com> 1d7e661b
@REPLYADDR none) (albert
@REPLYTO 2:5075/128 none) (albert
@CHRS: CP866 2
@RFC: 1 0
@RFC-References:
<20230707102938.23@kylheku.com>
@RFC-Message-ID:

@TZUTC: 0200
@TID: FIDOGATE-5.12-ge4e8b94
In article <20230707102938.23@kylheku.com>,
Kaz Kylheku  <864-117-4973@kylheku.com> wrote:
>On 2023-07-07, albert@cherry.(none) (albert)  wrote:
>> I`m trying to implement mal on ciforth
>> https://github.com/kanaka/mal
>> Amounts to implementing a dialect of lisp using a dialect of Forth.
>>

(much appreciated insight)

>
>If you`re writing code in Forth to make that work, then of course
>that is your problem.
>
>If you`re making a Forth from scratch, you have to implement
>several stacks yourself.
>
>If you`re making a Lisp from scratch, you have to implement
>environments.
>
>The simplest possible implementation of environments is stack-like.
>The environment is the head of an association list, which looks like
>this:  ((b . 1) (a . 2)) for an environment which contains two
>variables a and b bound to values 1 and 2.

That is available in Forth under the name wordlist.
There is a structure name VOCABULARY that have names and
traditionally are linked among themselves, that can be used
to point to outer environments.

>
>A new binding is created with cons:
>
>  (cons (cons `c 3) previous-env)

In my forth this is implemented as
[``set`` and ``get`` is the name prescribed by mal.]
    \\ Add  symbol  value  to the current.
    : set >R $, R@ >NFA ! R> CURRENT @ LINK ;
Note that each of these components are available in the Forth
core.
Finding a name through a recursive environments is done by
\\ For sc  env-wid  , return  item  . or throw. Follow outer links.
: get
    BEGIN DUP >R  (FIND) DUP 0= WHILE
            DROP R> WID>VFA @ DUP 0= 8010 ?ERROR
    >WID REPEAT
    NIP NIP RDROP ;
Likewise each of the components are present in the Forth core.
Not necessarily ISO standard words, but language components
needed to implement Forth that are repurposed.

>
>In some Lisps like Common Lisp, there is an acons for this:
>
>  (acons `c 3 previous-env)
>
>a new env is returned which looks like ((c . 3) (b . 1) (a . 2)).
>
>The new environment doesn`t clobber the old one; the environment
>is a local variable in a recursive interpreter, passed around through
>its recursion.
>
>That`s a reference model for a lexically scoped Lisp that came
>into the Lisp culture mainly via the Scheme influence.
>
>A lexically scoped Lisp doesn`t have to reveal to the programs
>the detailed representation of environments. Unless a special
>escape hatch is provided for it, programs don`t see the hidden
>"env" variable.  This is a good thing because it allows programs
>to be compiled. Compiled code uses a radically different
>representation of the environment.

This recursive fibonacci function  works
(def! fib (fn* (N) (if (= N 0) 1 (if (= N 1) 1 
    (+ (fib (- N 1)) (fib (- N 2)))))))

So the idea that Forth dictionary entries can serve as lisp "objects"
and that wordlists can serve as hashes has worked so far.

>Kas
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: 5005/49 5015/255 5019/40 5020/715 848 1042
4441 12000 5030/49 1081
SEEN-BY: 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



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

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