On Tuesday 13 July 2004 14:27, Florian Gross wrote:
> Sean O'Dell wrote:
> > Here's a question: are "pure" functional programming languages
> > implemented according to their own rules?  Internally, do they also never
> > use variables? My guess is: no, or almost never.  They break the rules
> > internally to provide an interface that adheres to the rules.
>
> It depends. Functional languages implemented in functional languages
> will be written in a functional style of course. C is no functional
> language, but most function language interpreters are written in C where
> you have so many side effects that you *have* to capture different
> states into variables.

But how are they usually implemented?  In ASM, C, ... ?

> The idea of functional languages is that the only thing a function is
> able to give to the outside is its return value.

Precisely.  What is returned is most important; functions must return 
consistent results for a given set of parameters, regardless of when they are 
called or how often.

> In such a pure functional world variables are no longer needed, because
> you can just use the function call itself where you would otherwise need
> to use the value that was captured to the variable.

But within a function, local variables don't affect the return value.  True, 
every new function a developer writes could be simply nested calls to other 
functions, but for readability, local variables are very helpful, and as long 
as they're not global or stateful, they don't affect the return value, so to 
the outside world it's still just a function.

> > They break the rules internally to provide
> > an interface that adheres to the rules.  In my opinion, a "pure"
> > functional language would allow you to develop your own functions and use
> > local variables so long as your functions interacted predictably with the
> > outside world.
> > It wouldn't be a "pure" functional language, but I would still call it a
> > functional language.
>
> Ruby doesn't use Objects at all in its implementation. In fact C doesn't
> even have Objects. Yet Ruby is a pure object-oriented language.

Yes, precisely.  My point for asking was to illustrate how there are two 
facets to any language design: the usage and the implementation.  Writing 
code in a language functionally, and writing new functions to extend the 
language are two different things, in the sense that how a language is used 
is your goal, but how it is implemented (or extended) can be anomalous to 
that goal.  You make exceptions for yourself when implementing a language, 
just so long as the end result is what you intended.  Likewise, if you use 
local variables within a function, so long as to the outside world (the end 
result) the function still behaves properly, the allowance of local variables 
doesn't detract from the language's designation as a "functional language" 
except in the very, very purest sense.

> The implementation really has nothing to do with this IMHO. It's not
> really part of the interface after all. :) (And there can be multiple
> interpreters for the same language all written in different languages of
> course. The really interesting parts of this are language interpreters
> that are written in the very same language that they interpret.)

Think of new functions that developers write in the language as part of the 
implementation itself.  You can give them tools to write new functions in the 
language which don't allow them to break the functional language paradigms, 
such as local variables, just like you can implement a functional language 
such a C, which is definitely NOT a functional language.

	Sean O'Dell