:: Re: [DNG] Wirth's law
Página Inicial
Delete this message
Reply to this message
Autor: Didier Kryn
Data:  
Para: dng
Assunto: Re: [DNG] Wirth's law
Le 25/07/2016 00:55, Steve Litt a écrit :
> On Sun, 24 Jul 2016 23:30:47 +0200
> Didier Kryn <kryn@???> wrote:
>
>> Le 24/07/2016 22:37, Jaromil a écrit :
>
>>> nowadays the closures paradigm (basically fifo pipes of pointers to
>>> stateless functions) is used much more than all that mutex and
>>> semaphore old stuff. i.e. golang adopted closures since the
>>> beginning with great success.
>>>
>>> ciao
>>       Don't know what a closure is, although I heard of it long ago on
>> this list. According to Wikipedia, it is "a record containing a
>> function and its environment".
> Hi Didier,

>
> I've never encountered closures as described by Jaromil, but they're a
> pretty handy thing easily done in many languages, with Lua leading the
> list. Here's something that might help explain a little bit:
>
> http://troubleshooters.com/codecorn/lua/luaclosures.htm
>


     Thanks, Steve. It confirms my further reading of Wikipedia's article.


     In languages like C, C++ or Ada, it is impossible to use a function 
to create a closure, because they store variables local to the 
subprogram (then creator function) in the stack. It is well known that 
Java allocates everything from the heap, making this easier.


     However there are tricks to do it in really many languages:
https://rosettacode.org/wiki/Closures/Value_capture


     In Ada this resorts to instantiate a special type of object for 
every closure and then initialize it by a special kind of invocation. 
This special object, behind the scene, contains a mutex :-(, but this 
one could cause contention only when initializing the closure, which has 
no reason to happen. Nevertheless it looks contorted.


     Didier