Remco Hh said:
I am reading stuff about functional programming in ruby.
what i do more lately is this:
var = <condition> ? "val1" : "val2:
instead of:
<condition> ? var="val1" : var="val2"
is the first line also an example of functional programming?
This might be considered a syntactic detail.
Functional programming is characterized by the use of mathematic
functions as a model of computation, which avoids state and mutable
data.
There's no notion of mutation in the usual mathematical objects (it's
possible to modelize state and mutation mathematically, but it
involves more complex structures).
So, if you assign only once each variable var, it can be considered as
a binding, that is like a mathematical "variable".
When we say mathematically "let y0 be f(0)", the variable y0 doesn't
change (it's a constant really).
Notice that avoiding state is rather antinomic to Object Oriented
Programming, since objects are defined by the encapsulation of both
state and program. If you remove state, there remains only program,
that is functions.
Well, you may keep objects, but without mutation, that is you may bind
values to an object instance variable only at initialization time, and
once the object is created, it mustn't change.
http://groups.google.com/group/comp...+group:comp.lang.ruby+&qt_g=Search+this+group