CS 330 Lecture 37 – Sundries
Agenda
- more on hijacking a language
- applicative- vs. normal-order evaluation
- writing an if macro
- macros in C
- dangers of normal-order evaluation of expressions with side-effects
- list ranges
- list comprehensions
- lazy evaluation
TODO
- http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf
- http://www.haskell.org/haskellwiki/Why_Haskell_matters
Code
macros.ss
(define myif (lambda (predicate? true-expr false-expr) (cond (predicate? 1) (else 0)))) (define-syntax spiffy (syntax-rules () ((spiffy predicate? true-expr false-expr) (cond (predicate? true-expr) (else false-expr)))))
numbers.cpp
#include <iostream> #define MAX(a, b) (a > b ? a : b) int ReadInt() { int i; std::cin >> i; return i; } int main() { /* std::cout << "MAX(5, 7): " << MAX(5, 7) << std::endl; */ std::cout << "MAX(#, #): " << MAX(ReadInt(), ReadInt()) << std::endl; return 0; }
haskfun.hs
nsum 0 = 0 nsum n = n + nsum (n - 1) plus a b = a + b
Haiku
There’s good in routine.
You stop tolerating crap.
You fix stuff. You smile.
You stop tolerating crap.
You fix stuff. You smile.