|
|
|
|
|
by q_eng_anon
2495 days ago
|
|
this is interesting - thanks for your response. I'm having a hard time understanding the program you supplied though, the subsequent description did not really help (probs more my fault than your own). I certainly understand the visitor pattern (and have had a sneaky suspicion it is important) but the lambda calculus, not so much. What type of syntax is the program you supplied in - is it more of a pseudocode or an actual formal language? thanks for the search keywords - definitely helped - if you have a favorite textbook/arxiv reference/author on this stuff, those would be greatly appreciated as well. |
|
True = (lambda (t f) (t))
-- Let True be the function that takes two parameters t and f and returns the first, t. --
False = (lambda (t f) (f))
-- Let False be the function that takes two parameters t and f and returns the second, f. --
If = (lambda (b tr fa) (b tr fa))
-- Let If be the function that takes three parameters, and applies the first parameter b to the second and third parameters. --
Notice that if the parameter b is the True value above, 'b tr fa' will return 'tr'. If 'b' is False, 'b tr fa' will return 'fa'
So it follows that this will pass either "It was true!" or "It was false!" to 'display', waving aside all the stuff you have to define that makes 'display' and STRINGS work as you'd expect.This is where it becomes clear that you need a lazy system for this to make sense. In an eager system all three of the parameters to 'If' are evaluated and then their values are substituted into the body of 'If'. In a lazy system the expressions for the values are substituted for the parameters in the body, so only the parameter 'b' and one of the other parameters will be evaluated.
When I play around with functional languages I would just write
You could also write this in (I think this is) Scheme: Except that Scheme isn't usually lazy.