Re: Difference between method and block - with examples

"Shashank" <[email protected]>
Newsgroups gmane.comp.lang.io
Message-ID <[email protected]>
Hi,

--- In [email protected], Tiogshi Laj <tiogshi@...> wrote:
>
> That doesn't work because := creates a new slot with that binding if one
> doesn't exist in lexical scope. You want to use just = there in order to
> assign to the inherited slot instead of creating a new one.
> 

That *almost* worked, except one case:

n    := 10
mthd := method(i, i + n)
blk  := block(i, i + n)
foo  := method(n = 20; mthd(3))
bar  := method(n = 30; blk)

mthd(1)     println  # 11 (as expected)
blk call(2) println  # 12 (as expected)
foo         println  # 23 (as expected)
bar call(4) println  # 34 (but really expected 14)

Basically, I am expecting that method() uses local variables visible in the context of the caller (hence dynamic closure) and block() uses local variables visible in the context of its definition (hence static closure). 

May be my expectations are tinted by my understanding of static vs. dynamic closures. Or the lack thereof :)

- Shashank
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.