Hi, Casey
It'll be great if you can tell the name of the parameter.
The assignment to block argument does actually work with no error. So it looks like "allow block argument assignment" parameter is enabled. Here is the example:
[:x | x := x + 1. x] value: 1 => 2
But as we can see from examples in the previous post it behaves in a strange way.
Oh yes, SICP it's a great book. I've read it with great pleasure. And actually it's thats why I try to understand better the semantics of block's arguments. Because in functional programming (and scheme also) the function's arguments and local variables are actually the same things. (local variables is just syntactic sugar for function arguments). Here is a one-to-one mapping in scheme for examples in previous post and they behaves equally (as expected).
======================= version with assignment to function argument
(define (make-acc acc) (lambda (n) (begin (set! acc (+ acc n)) acc)))
(define a1 (make-acc 10))
(a1 1) => 11 (a1 1) => 12 (a1 2) => 14
====================== version with assignment to local variable
(define (make-acc acc) (let ((define total acc)) (lambda (x) (begin (set! total (+ total x)) total))))
(define a1 (make-acc 10))
(a1 1) => 11 (a1 1) => 12 (a1 2) => 14
Some clarification: I'm not going to program in functional style with Smalltalk. The plan is to fully utilize the OOP in learning purposes. That's why I dive into ST :-). I'm just trying to understand the semantics of constructs in the language. In either case there are functional tools in ST (methods in Collections inject:to: collect: etc.) and blocks are essential part of it. Therefore it's good to understand semantics of block.
Addition: I've saw somewhere in the net the term "Closure compiler" for Squeak. Maybee it can be the key to understanding the problem. But have no time to dive into.
-- View this message in context: http://forum.world.st/Modify-block-closure-parameters-tp4702118p4702265.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.