From 4daf6d26c2744941d8713ca16c5168553d79fa46 Mon Sep 17 00:00:00 2001 From: Jim Date: Sun, 1 Feb 2015 00:31:44 -0500 Subject: [PATCH] update week1 notes --- week1.mdwn | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week1.mdwn b/week1.mdwn index 56b05d13..c9aee3bc 100644 --- a/week1.mdwn +++ b/week1.mdwn @@ -363,7 +363,7 @@ When the pattern `p & ps` is matched against a non-empty set, we just arbitraril might evaluate to `(20, {10, 30})` or to `(30, {10, 20})` or to `(10, {30, 20})`, or to one of these on Mondays and another on Tuesdays, and never to the third. You cannot control it or predict it. It's good style to only pattern match against sets when the final result will be the same no matter in what order the values are selected from the set. -A question that came up in class was whether 'x + y` could also be a pattern. In this language (and most languages), no. The difference between `x & xs` and `x + y` is that `&` is a *constructor* whereas `+` is a *function*. We will be talking about this more in later weeks. For now, just take it that `&` is special. Not every way of forming a complex expression corresponds to a way of forming a complex pattern. +A question that came up in class was whether `x + y` could also be a pattern. In this language (and most languages), no. The difference between `x & xs` and `x + y` is that `&` is a *constructor* whereas `+` is a *function*. We will be talking about this more in later weeks. For now, just take it that `&` is special. Not every way of forming a complex expression corresponds to a way of forming a complex pattern. Since as we said, `x & xs` is a pattern, we can let `x1 & x2 & xs` be a pattern as well, the same as `x1 & (x2 & xs)`. And since when we're dealing with expressions, we said that: @@ -419,6 +419,9 @@ The role of `_` here is just to occupy a slot in the complex pattern `(_, b, _, One last wrinkle. What if you tried to make a pattern like this: `[x, x]`, where some variable occurs multiple times. This is known as a "non-linear pattern". Some languages permit these (and require that the values being bound against `x` in the two positions be equal). Many languages don't permit that. Let's agree not to do this. +### Case and if/then/else ### + +*More coming* ### Recursive let ### -- 2.11.0