Nп/п : 34 из 93
 От   : none) (albert                       2:5075/128        15 авг 23 08:44:44
 К    : Anton Ertl                                            15 авг 23 09:47:02
 Тема : Re: Closures
----------------------------------------------------------------------------------
                                                                                 
@MSGID:
6dbb19e9
@REPLY: <2023Aug14.161756@mips.complang.tuwien.ac.at>
46d9c335
@REPLYADDR none) (albert
@REPLYTO 2:5075/128 none) (albert
@CHRS: CP866 2
@RFC: 1 0
@RFC-References:
<2023Aug14.161756@mips.complang.tuwien.ac.at>
@RFC-Message-ID:

@TZUTC: 0200
@TID: FIDOGATE-5.12-ge4e8b94
In article <2023Aug14.161756@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@cherry.(none) (albert) writes:
>>I finally understood what closures mean.
>>In Forth parlance it is a search order that is kept with an
>>Forth word.
>
>That view leads down to boy compilers (in Knuth`s man-or-boy test),
>and at best (if you save and restore the variables on function entry
>and exit) dynamically-scoped Lisp.
I`m an amateur. I implement MAL. I don`t know whether that is a
dynamically-scoped Lisp. Actually my goal is to prove that
Forth is capable of parsing lisp itself, with a modular parser
in the style of BEGIN WHILE REPEAT words.
For example the rule that comma is to be treated as blank space
translate to the rule:
    : , ; PREFIX

>
>>An environment is a wordlist,
>
>A wordlist has only one instance of each word in a wordlist.
Okay, so we have multiple instance of a wordlist.

>
>An environment in a statically-scoped language is a set of local
>frames, where each local frame is created dynamically when the
>function to which the frame belongs is called.  So if a function has
>two instances at the same time (e.g., in recursion), a wordlist is
>insufficient.
That would mean that
    (def! fib (fn* (N) (if (= N 0) 1
            (if (= N 1) 1 (+ (fib (- N 1))
            (fib (- N 2)))))))
would fail,  but it isn`t:
(fib 10)
89

Also the quine tests succeeds. It was commented out of the tests,
because the line was too long. (and it is too long for a usenet post,
sorry). That was not a restriction in my implementation.

;;;;; Test quine
  ((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote
(fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
 ;=>((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote
(fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))

What fails is:
   ( ( (fn* (a) (fn* (b) (+ a b))) 5) 7)
         (b) (+ a b))) 5) 7) ? ciforth ERROR # 8010
Error 8010 means that a symbol is not found in the nested environments.
`` a `` is not found.
The phrase clearly means that in the environment that `a has the
value 7, a new instance of the function has to be generated.
>
>You can use wordlists to store the offsets of variable within the
>frames, but you have to manage the frames separately.
I think I do with the proposed mechanism.
We shall see.

>
>- anton
-- 
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 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    
                                                                                
В этой области больше нет сообщений.

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