[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:04131] Re: Function objects. was: What are you using Ruby for?

From: Johann Hibschman <johann@...>
Date: 2000-07-19 17:38:17 UTC
List: ruby-talk #4131
Dave Thomas writes:

> It looks like my previous reply to this may have been lost, so I'm
> re-posting it.

I got it via email and have been thinking about it.


> One of the things about functions is that referencing one in a pure OO 
> language requires that you at some point bind it to an object. A
> function on its own means nothing. Take the humble '+' operator, for
> instance. Send it to a number, and you get addition; send it to a
> string, concatenation.

This does seem a bit weird to me, though.  A function is a function is
a function.  It's a mapping from a domain space to a range space.  As
such it's as real as anything.  The weirdness arises for me because
most languages have some syntactical sugar to make these nicer to deal
with; in Ruby it looks like I'm best off explicitly declaring them as
a class and using them that way.

> Then the code might look something like:

>   calc = Calculator.new

>   register_function("f1", calc.method(:f1), "computer it")
>   register_function("g1", calc.method(:g1), "computer other")

This doesn't help me generate new functions from old ones, like the
variable-changes I did earlier with g_from_f.  It does encapsulate the
functions well, but at the cost of the slight strangeness of using a
class simply to provide a namespace.

In any case, this is wandering far astray from the original point.

I think the conclusion is that I can't do things quite as simply as I
can in languages where functions are first-class objects, which is not
surprising.  This isn't necessarily a bad thing, since some of the
sneaky tricks used to do that may be very hard to read.  (Like just
about any Scheme program that uses call-with-current-continuation.)

--J

-- 
Johann Hibschman                           johann@physics.berkeley.edu

In This Thread