10.07.2015 Views

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

- 151 -λdummy.e2Instead, we have <strong>to</strong> change our notation for if. Now:if then else will be replaced by:cond λdummy. λdummy. Thus and will be inserted straight in<strong>to</strong> the call <strong>to</strong> cond without evaluation.We have introduced the delay through a textual substitution technique which is equivalent <strong>to</strong> normal order evaluation.Alternatively, we could redefine our def notation so it behaves like a macro definition and then our first attemptwould work. A macro is a text substitution function. When a macro is called occurences of its bound variables in itsbody are replaced by the arguments. Macros are used for abstraction in programming languages, for example in C andin many assembly languages, but result in the addition of in-line text rather than layers of procedure or functions calls.Here:def = might introduce the macro and subsequent occurrences of: would require the replacment of in with the corresponding followed by the evaluation of the resulting This would introduce macro expansion in a form equivalent <strong>to</strong> normal order evaluation.Here we will redefine if ... then ... else .... Now, true and false must be changed <strong>to</strong> force theevaluation of the selected option. This suggests:def true x y = x identitydef false x y = y identityFor arbitrary expressions and :and:if truethen else ==cond λdummy. λdummy. true ==true λdummy. λdummy. -> ... ->λdummy. identity ->if falsethen

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!