ser / germane-software.com (Sean Russell) writes:

> Mikael Brockman <phubuh / phubuh.org> wrote in message news:<87llhx2hec.fsf / phubuh.org>...
>> Lots of functional languages lack pattern matching.  Scheme, for
>> example.  One can write Scheme-styled code in Ruby.
>
> In this, and following posts, you make the claim (directly and
> indirectly) that all languages are functional languages, rendering the
> term "functional language"  meaningless, or at least useless.  I
> oppose attempts to generalize words into meaninglessness.

No.  I claim that it's possible to write functional code in any
language, provided it is sufficiently expressive.  I don't claim Ruby is
a functional language.

> There *are* good, useful definitions of what constitutes a functional
> languages, and Ruby does not match the criteria for most of them. 
> Probably the most fundamental of all criteria is that the language
> does not allow side-effects, such as assignment.

I think that's a very poor criteria, since most language considered to
be functional don't fulfill it.  See Scheme, Lisp, O'Caml, SML, etc.
Haskell is the only mildly popular language I know of that actually
disallows side-effects, and its implementations consistently provide a
way to evaluate imperative code within the system.

> I'll concede that, if you're allowed to write a lot of non-functional
> code in the form of a library, it is possible to write a Ruby
> application that is visually indistinguishable from a purely
> functional program.  I'll even grant that it is possible to write a
> few very short programs using only the inherited functions in Kernel,
> ignoring the fact that math in Ruby is, in fact, method calls on
> objects rather than function calls or primative operations.  However,
> I'll maintain that this is a far cry from satisfying the claim that
> one can do functional programming in Ruby.

Arithmetic is indeed implemented as method calls, but that's an
implementation detail.  And that embodies my fundamental point:
paradigms are phenomena in the heads of the programmers, not properties
of the language.

>> I disagree.  Ruby lacks purely functional I/O, but so do Scheme and
>> Lisp.  I don't see why Scheme would surpass Ruby's functional
>> programming ability.
>
> Because they satisfy several other criteria that are usually
> attributed to functional programming languages, such as support for
> optimized tail recursion.  They may not be "purely" functional, but
> Ruby is about as contaminated a functional language as is possible to
> achieve.

Common Lisp doesn't specify the optimization of tail calls.  The
differences between Ruby and Common Lisp are mostly superficial.

>> You're mistaken in believing that functional programs must lack method
>> calls.  Scheme's CAR and CDR are just as `object-oriented' as Ruby's
>> first and tail.  Ruby just makes it explicit.
>
> No they aren't.  car and cdr aren't methods on objects.  They are
> functions that take objects as arguments.

They are both operations on an object.  The matter in which you choose
to see that is in your head.  You choose to see CAR and CDR as
non-methods; I can just as easily choose to see them as methods.

> Now, a better example would have been to point out OCaml, which is
> *both* functional *and* OO, something which I believe is fundamentally
> impossible, in that it can't be pure OO and pure functional.  However,
> it has a lot of features associated with functional languages, and
> many features associated with OO, so it can claim to be a functional
> language with OO capabilities.

Object-oriented programming is very easily done without the explicitly
OO parts of O'Caml, because the paradigm is in the programmers' heads.

  mikael