From: dblack@... Date: 2003-09-25T12:15:22+09:00 Subject: Re: value binding and function binding Hi -- On Thu, 25 Sep 2003, Vivek Nallur wrote: > Hi > > I was just wandering through some lisp code and I saw this: > (let ((x 1)) > (flet ((x (y) (+ x y))) > (x x))) > > (I'm not sure if the indentation came out properly) > > A transliteration(?) of this code gave me an error! > > [nvivek@indus nvivek]$ cat t.rb > x = 1; > def x (y) At this point, your x variable is out of scope, so this: > x += y gives you that error (because here, x is uninitialized). > end > x x > > [nvivek@indus nvivek]$ ruby t.rb > t.rb:3:in `x': undefined method `+' for nil:NilClass (NoMethodError) > from t.rb:5 > > All I want to do is to check if ruby supports the same identifier having > both a value binding as well as a function binding. Yes, both inside and outside the method (separately): ruby -e 'def x(y); x = y; puts x; end; x = 1; x x' => 1 David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav