From: "David A. Black" Date: 2003-12-08T03:26:35+09:00 Subject: Re: newbie question Hi -- On Mon, 8 Dec 2003, nainar wrote: > I am beginning to understand this: > If you assign to the variable within the function the original is NOT > modified. > > if you modify the variable within the function then the original is modified. > > It means if the variable is a simple type like a numeric it cannot be > modified. If I try something like: Variables are untyped; there's no such thing as a variable of a simple type. (This isn't just pickiness; it actually makes a big difference.) > v=99 > def f1(n); n=n*n ; end > f1(v) > it will not work. Yes it will. (Try it :-) Any time you have a variable name on the lhs of an assignment, the variable of that name gets assigned a new reference. n = 1 n = 2 n = "hi" n = 99 n = n * n n = n - 30 etc. Every time you put 'n' on the lhs, you're starting from scratch; previous values of 'n' have no relevance. (On the rhs, of course, the pre-assignment n is used to evaluate the expression.) Literal integers are different from variables; you can't do this: 99 = 2 since that would screw the math up quite a big :-) > Why can't we have something simpler/more explicit like in C or even Perl?. Have another look at how Ruby does it. :-) David -- David A. Black dblack@wobblini.net