From: ichimal@... Date: 2003-02-03T20:33:18+09:00 Subject: Re: Local variables & blocks Hi folks. How do you do? In message "Re: Local variables & blocks" on 03/02/03, mats writes: >|I just wonder what the second invocation of blocktest() will print. Since >|there is no iteration, no assignment to 'foo' will have taken place. Is >|this an error or will 'foo' be initialized with 'nil'? I guess 'nil' >|initialization will be more reasonable because it saves an additional test. > >nil. Right again. ;-) I think, it should be a first-class special value like #. For example: def blocktest(args) args.each do |arg| foo = foo and arg end foo end arg1 = [] arg2 = [nil, nil, nil] result1 = blocktest(arg1) result2 = blocktest(arg2) ... case 1: blocktest returns a nil as the non-initialized value: if result1 then do_something elsif arg1.length > 0 then # Is arg1 really [] yet? do_something else do_something end case 2: blocktest returns a # case result1 when nil do_something when # do_something else do_something end The value nil already have a special mean. Double meaning may be more harmful idea than shadowing, I think. c.f. #f, nil and () in Lisp/Scheme. I'm sorry my poor English. Thanks. ---- 1002.(ichimal@fenix.ne.jp) SUZUKI Shingo