Re: [stack] Re: Barebone implementation of concatenative language in c or c++
"William Tanksley, Jr" <[email protected]> Tue, 20 Jul 2010 21:18:15 -0700
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
Don Groves <[email protected]> wrote: > William Tanksley, Jr wrote: >> Don Groves <[email protected]> wrote: >>>>>> "William Tanksley, Jr" <wtanksleyjr@> wrote: >>>>>>> Laziness is one of the things that can't easily be imported to a >>>>>>> concatenative language. >>> It seems to me that laziness can be implemented simply by >>> encapsulating all data in functions. If a particular function >>> is not called, that data is not evaluated. What am I missing? >> Data isn't supposed to be evaluated, of course; I think you meant >> encapsulating all functions in data rather than the other way around. > OK, guess I may need some hand-holding here: No... It's just unclear presuppositions. Thanks for making them clear by asking about them. > Isn't call-by-reference essentially equivalent to lazy evaluation? No; C++ allows call by reference semantics (explicitly specified, of course) without being lazy at all. An early Fortran had implicit call by reference, again not lazy (but, I'm told, very dangerous). I don't use Perl, but I'm told it's call-by-reference. Wikipedia just reminded me that you're thinking of "call by name" or "call by need", but those are simply ways to achieve lazy evaluation. > If the called function doesn't need a certain parameter during a > particular call, that parameter will not be evaluated. So, parameters > (data) are only evaluated when needed, i.e., they are lazy. That IS what lazy evaluation is, yes. > In a call-by-value environment, It seems to me that encapsulating > all data in functions yields the same effect as call-by-reference. If > a parameter is not needed, its evaluating function will not be called. This gets confusing to me, so hold on tight... :-) In order to pass a function to a procedure, the function has to be available as data. If it's not, you can't pass it. Now, if your language is lazy (or non-strict) this doesn't matter; you can avoid executing the function by never mentioning its parameter on an execution path. This allows languages that don't provide higher-order functions to still be very expressive. > don -Wm