From: zuzu Date: 2004-07-10T05:32:59+09:00 Subject: Re: Functional Ruby (Re: Why I don't use Ruby.) On Sat, 10 Jul 2004 05:07:30 +0900, Sean Russell wrote: > "Sean O'Dell" wrote in message news:<200407081308.50197.sean@celsoft.com>... > > You can have variables in a functional language, but what you can't have are > > globals that act statefully, causing any functions you write to return > > different values when passed the same parameter values. You can have > > (pseudocoded): > > > > function myfunc(a) > > b = anotherfunc(a) > > return sin(b) > > end > > Technically, in a purely functional language, you also shouldn't be > able to reassign a new value to 'b', once you set it. This has > nothing to do with the scope, and indeed, there are no such things as > "variables" in *purely* functional languages, because they shouldn't > vary. What you can have is aliases for values. Haskell, for example, > allows you to use "let" and "where" to assign values to aliases that > look alot like variables, but are immutable. > > --- SER how are variables in ruby "mutable" then? ruby assignment merely labels objects. a = 42 a = 64 here, ruby created a Fixnum object with a return value of 42, and assigned it the label "a". next, ruby creates another Fixnum object, this one with a return value of 64, and points the label "a" to it instead. the Fixnum object with a value of 42 still exists... but if it goes unused the garbage collector will eventually stroll along and trash it. i should double-check this, but i think ruby allows for anonymous (unlabeled) objects just as it allows for anonymous functions. but referencing such objects would require tricks of introspection and asking objects "who's willing to reply to this message?" -z