is this considered functional?

R

Remco Hh

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?
 
P

Pascal J. Bourguignon

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,474
Latest member
AntoniaDea

Latest Threads

Top