Elan said:
    I wonder what John C. thinks about this problem.

I think there are a few interesting questions to ask:

1.  What are the `correct' rules for function application,
    variable scoping, and objects?

2.  Are these rules useful?

3.  Is the current *implementation* of REBOL faithfully following
    these rules?

4.  Is the *next* implementation of REBOL likely to behave
    differently?

-----

One approach to answering these is the `Gump' approach:  REBOL is
as REBOL does.  We *define* `correctness' as whatever the current
implementation does.  This finesses questions 1 and 3, but questions
2 and 4 are interesting:

The current implementation seems to be fairly well behaved as long
as you don't attempt to return functions outside of the scope in
which they are defined.  However, functions aren't
first-class objects if you can't return them
as values.  And since function invocation causes visible side effects,
REBOL's claim to being a `functional' language is on very shaky
ground.

Every version of REBOL has either made subtle or drastic changes in
how variables are scoped.  There is no reason to believe that the
current way things work will not change in the next release.  In fact,
most of us hope that it will be less `buggy'.

But if REBOL is what REBOL does, then REBOL is, by definition,
bug free.  And the question arises, if REBOL is bug free, why
does it keep changing?

As users of REBOL, it would be bad if we could not predict the
behavior of our programs in future versions of REBOL, so I don't
think that the `Gump' viewpoint is very useful.

----

Another view is that there *is* a formal model of what REBOL is
supposed to do.  This has some problems, too.

If there are `correct' rules for function application, variable
scoping, and objects, why is REBOL Tech. so adamant about keeping
them secret?

Are functions supposed to be able to return functions as values,
or are they supposed to cause visible side effects in the interpreter?

Is the GC buggy when it collects contexts or do contexts have a
limitied lifetime?

Where does the current implementation of REBOL fail to faithfully
execute the rules?

-----

Elan and Ladislav are currently discussing the observed behavior of
REBOL when you attempt to return an inner function.  Since REBOL
hasn't documented what is supposed to happen, the question of whether
this is a `bug or feature' is undecidable (although if the behavior
changes in the next release, I guess it is a bug in this release).

We can, however, ask whether the current behavior is useful.

I have to agree with Ladislav that the current behavior is not
useful because it makes it impossible to predict what will happen
when you invoke a function that has been returned from another
function without a complete analysis of the history of the code,
and without knowing whether the GC has run.

----

Jeff asks:

    Maybe I am missing the point, but what's wrong with:

    composite: func ['f 'g][func [x] compose [(f) (g) x]]

Jeff's code doesn't work in this case:

   funny-func:  composite
                    func [x] [x + 1]
                    func [y] [y * 2]

Nor does the technique generalize:

   mapper: func ['f] [func [block] compose [foreach element block [(f) 
element]]]








______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Reply via email to