summaryrefslogtreecommitdiffstats
path: root/ps05_pattern_matching/bnewbold_ps05.txt
blob: 6ce38a1580a5ffc5d5f97bc91e72f8f9a6544ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
;;; 6.945 Problem Set #5 Comments
;;; 03/11/2009
;;; Bryan Newbold <bnewbold@mit.edu>

Note: Problem numbers were totally off! Jeez! ;)

Problem 5.1: Multiple Matches 
--------------------------------
The multiple suceeds are due to the looping let expression ("lp") in 
match:segment. The first segement match attempt is with n=0, which is why the
first succeed statement has x null. This is a valid match with y equaling
(b b b b b b), so the success procedure is called and this match printed, but
then the failure causes evaluation to drop back to "lp", with n now incremented
to 1, and the process continutes until n=4, which has no matches at all and
the #f thunks all the way down to the floor.

Problem 5.2: Multiple Matches 
--------------------------------
I allowed match:element declarations to have an optional predicate; the
procedure corresponding to the predicate symbol is pulled from the nearest repl
environment. A problem with my implementation is that the predicate is only
checked for the first reference to the variable; if the predicate is different
or only specified in one of the later references, the right thing doesn't
happen.  Eg,

((matcher '(a (? b) (? b integer?) c))
  '(a t t c))
; ((b t))
; should be #f?

Also the predicate has to be a simple symbol existing in the environmnet,
instead of a lambda expression, maybe I should have used apply?

[see code in bnewbold_ps05_work.scm]

Problem 5.3: Multiple Match Implementation
--------------------------------
Ugh, I should really read these problem sets through the whole way first. See
implementation above, a somewhat ugly method.

Problem 5.4: ?:choice
--------------------------------
[see code in bnewbold_ps05_work.scm]

Problem 5.5: ?:pletrec, ?:ref
--------------------------------
I couldn't get match:list? to override for some reason, so '() isn't handled
with an eqv combinator like it should be.

I used a global dictionary *pattern-table* which gets added to by each pletrec
statement and reset to '() by every matcher expression.

[see code in bnewbold_ps05_work.scm]

Problem 5.5: restrict
--------------------------------
Somewhere along the line i've made some horrible mistake handling lists because
the null list isn't handled right. But I can't figure out what's wrong, the
next step for me would be to rewrite everything; my namespace gets polluted
with old versions of handlers pretty fast.

[see code in bnewbold_ps05_work.scm]