From: Sean O'Dell Date: 2004-07-11T04:54:18+09:00 Subject: Re: Functional Ruby (Re: Why I don't use Ruby.) On Saturday 10 July 2004 11:57, Sean Russell wrote: > "Sean O'Dell" wrote in message > news:<200407091430.02799.sean@celsoft.com>... > > > You can modify values, as long as the value isn't a global (stateful > > data). The key is that the function has to represent the modification, so > > that when you call it with a given set of values, it always does the same > > thing. > > Sean, scope has nothing to do with this. It has to do with state, > within or without of any given scope. If you have a "variable" -- > some alias to a value -- and you change it, even within a limited > scope, you've changed state. Re-assignments are not allowed in pure > functional programming languages. You're right, not in the strictest sense of the term. But there are two things you do as a programmer: program in the language and add to the language. If a functional programming language lets you write your own functions, so long as you don't make use of global/stateful variables so your functions always return the same value in response to parameters passed, no matter how many times it is called or when, to the outside world, to the programmers calling your function, it makes no difference if you used variables within the scope of your function or not. Your function behaves predictably, and it fits well into an existing library of functions in a "pure" functional language. Do you see what I mean? You can allow local variables within the scope of a function, and to the outside world, the function has broken no rules. So long as it returns the same value always in response to a given set of parameter values, no one using the function can tell that it has broken a rule, and it doesn't affect the structure of the code. 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. 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. Sean O'Dell