Nп/п : 35 из 93
 От   : Kaz Kylheku                         2:5075/128        15 авг 23 07:33:15
 К    : none) (albert                                         15 авг 23 10:36:02
 Тема : Re: Closures
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <20230815002701.354@kylheku.com> 7dface35
@REPLY:
6dbb19e9
@REPLYADDR Kaz Kylheku <864-117-4973@kylheku.com>
@REPLYTO 2:5075/128 Kaz Kylheku
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <20230815002701.354@kylheku.com>
@RFC-References:
<2023Aug14.161756@mips.complang.tuwien.ac.at>

@TZUTC: -0000
@PID: slrn/1.0.3 (Linux)
@TID: FIDOGATE-5.12-ge4e8b94
On 2023-08-15, albert@cherry.(none) (albert)  wrote:
> 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)

fib is not capturing lexical closures. There are multiple instances, but
they are not accessible at the same time.  In particular, once any
activation of fib terminates, nothing accesses that instance of N any
more.

We can write fib in C, whose local variables turn to pixie dust when the
block scope ends, allowing a simple stack to be used for locals.

Lexical closures mean that the variables visible in any activation of a
function can live indefinitely.  Lexical closures are objects that can
escape from the context where they are created, and be invoked after
that context has terminated.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
--- slrn/1.0.3 (Linux)
 * Origin: A noiseless patient Spider (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    
                                                                                
В этой области больше нет сообщений.

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