Value binding and function binding

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)
x += y
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.

Comments?

-vivek

···

Smith & Wesson: The original point-and-click interface

Hi –

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

···

On Thu, 25 Sep 2003, Vivek Nallur wrote:


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

I was just wandering through some lisp code and I saw this:
(let ((x 1))
(flet ((x (y) (+ x y)))
(x x)))

At this point, your x variable is out of scope, so this:

x += y

gives you that error (because here, x is uninitialized).

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
Hmmm…Many thanks (btw, can I start with a capital letter after
ellipses?)

So, ruby does support having multiple bindings, but the

x += y
is a scoping issue(Would dynamic scope have helped?).

regs
Vivek

···

Nothing is lost until you begin to look for it.

irb(main):001:0> Hmmm = 4
=> 4
irb(main):002:0> Many = 4000000
=> 4000000
irb(main):003:0> Hmmm…Many
=> 4…4000000

;-))

One entry found for ellipsis.

1 a : the omission of one or more words that are obviously understood
but that must be supplied to make a construction grammatically
complete
b : a sudden leap from one topic to another

One entry found for embrown.

2 : to cause to turn brown

Finding this word whilst leafing through the dictionary
made it worth the research fee.

Couldn’t find emgreen, which (IMHO) could be useful at times.
Perhaps if there are any lexicographers in the group ???

daz

···

“Vivek Nallur” nvivek@ncst.ernet.in wrote:

Hmmm…Many thanks (btw, can I start with a capital letter after
ellipses?)