From 28013dcce4ce2ac3d56ed3b5c50671bb7ed84899 Mon Sep 17 00:00:00 2001 From: Ranjit Jhala Date: Sat, 8 Dec 2018 07:39:24 -0800 Subject: [PATCH] update page --- docs/lectures.html | 11 ++++- docs/lectures/07-egg-eater.html | 77 +++++++++++++++++++-------------- lectures.md | 3 +- lectures/07-egg-eater.md | 41 +++++++++++------- 4 files changed, 81 insertions(+), 51 deletions(-) diff --git a/docs/lectures.html b/docs/lectures.html index 4a6a87b..0ec8131 100644 --- a/docs/lectures.html +++ b/docs/lectures.html @@ -282,12 +282,19 @@

Lecture Notes

code -11/5 -Heap Data | [htm +11/19 +Heap Data html md code + +11/28 +Garbage Collection +html md +pdf +code +
diff --git a/docs/lectures/07-egg-eater.html b/docs/lectures/07-egg-eater.html index e9e96eb..028ed36 100644 --- a/docs/lectures/07-egg-eater.html +++ b/docs/lectures/07-egg-eater.html @@ -752,39 +752,31 @@

Constructing Tuples

Accessing Tuples

We can write a single function to access tuples of any size.

So the below code

-
yuple = (1, (2, (3, (4, 5))))
-get(yuple, 0) = 1
-get(yuple, 1) = 2
-get(yuple, 2) = 3
-get(yuple, 3) = 4
-get(yuple, 4) = 5
-
+
+
+
+def tup3(x1, x2, x3):
+  (x1, (x2, x3))
+
+def tup5(x1, x2, x3, x4, x5):
+  (x1, (x2, (x3, (x4, x5))))
+
+let t  = tup5(1, 2, 3, 4, 5) in
+  , x0 = print(get(t, 0))
+  , x1 = print(get(t, 1))
+  , x2 = print(get(t, 2))
+  , x3 = print(get(t, 3))
+  , x4 = print(get(t, 4))
+in
+  99

should print out:

0
 1
@@ -809,8 +801,27 @@ 

QUIZ

QUIZ

Using the above “library” we can write code like:

- +

What will be the result of compiling the above?

  1. Compile error
  2. diff --git a/lectures.md b/lectures.md index cf9fb9e..b157872 100644 --- a/lectures.md +++ b/lectures.md @@ -11,7 +11,8 @@ headerImg: books.jpg | 10/15 | Branches and Binary Operators | [html][lec4] [md][md4] | | [code][cod4] | | 10/24 | Data Representation | [html][lec5] [md][md5] | | [code][cod5] | | 11/5 | Functions | [html][lec6] [md][md6] | | [code][cod6] | -| 11/5 | Heap Data | [html][lec7] [md][md7] | | [code][cod7] | +| 11/19 | Heap Data | [html][lec7] [md][md7] | | [code][cod7] | +| 11/28 | Garbage Collection | [html][lec8] [md][md8] | [pdf][pdf8] | [code][cod8] | [lec1]: lectures/01-introduction.html [md1]: http://github.com/ucsd-progsys/131-web/blob/master/lectures/01-introduction.md diff --git a/lectures/07-egg-eater.md b/lectures/07-egg-eater.md index 0ffe424..36d790f 100644 --- a/lectures/07-egg-eater.md +++ b/lectures/07-egg-eater.md @@ -642,28 +642,20 @@ We can write a single function to access tuples of any size. So the below code ```python -yuple = (1, (2, (3, (4, 5)))) -get(yuple, 0) = 1 -get(yuple, 1) = 2 -get(yuple, 2) = 3 -get(yuple, 3) = 4 -get(yuple, 4) = 5 +let yuple = (10, (20, (30, (40, (50, false))))) in +get(yuple, 0) = 10 +get(yuple, 1) = 20 +get(yuple, 2) = 30 +get(yuple, 3) = 40 +get(yuple, 4) = 50 -def get(t, i): - if i == 0: - t[0] - else: - get(t[1],i-1) def tup3(x1, x2, x3): (x1, (x2, x3)) -def tup4(x1, x2, x3, x4): - (x1, (x2, (x3, x4))) - def tup5(x1, x2, x3, x4, x5): (x1, (x2, (x3, (x4, x5)))) @@ -718,7 +710,26 @@ What will be the result of compiling the above? Using the above "library" we can write code like: ```haskell -let quad = tup4(1, 2, 3) in + + +def get(t, i): + if i == 0: + t[0] + else: + get(t[1],i-1) + +get(t, 2) ===> get(t[1], 1) ===> get(t[1][1], 0) + + +def tup3(x1, x2, x3): + (x1, (x2, (x3, false))) + +let quad = tup3(1, 2, 3) in + quad = (1, (2, 3)) + quad[1] = (2, 3) + quad[1][1] = (3, false) + quad[1][1][1] = false + get(quad, 0) + get(quad, 1) + get(quad, 2) + get(quad, 3) ```