diff --git a/collects/redex/scribblings/tut.scrbl b/collects/redex/scribblings/tut.scrbl index 14a10b3d16..183aecdad8 100644 --- a/collects/redex/scribblings/tut.scrbl +++ b/collects/redex/scribblings/tut.scrbl @@ -89,11 +89,15 @@ @title[#:tag "tutorial"]{Amb: A Redex Tutorial} This tutorial is designed for those familiar with the call-by-value -λ-calculus (and evaluation contexts), but not Redex or Racket. +λ-calculus (and evaluation contexts), but not Redex. The tutorial works though a model of the λ-calculus extended with a variation on McCarthy's @racket[amb] operator for ambiguous choice@~cite[amb1 amb2]. +If you are not familiar with Racket, first try +@other-doc['(lib "quick.scrbl" "scribblings/quick")] or +@other-doc['(lib "more.scrbl" "scribblings/more")]. + The model includes a standard evaluation reduction relation and a type system. Along the way, the tutorial demonstrates Redex's support for unit testing, random testing, typesetting, metafunctions, reduction relations, @@ -212,6 +216,20 @@ elements of the sequence in different ways: (+ 5 6)))) (list/c match? match? match?)] +@exercise[] + +Use @racket[redex-match] to extract the body of the +function from this object-language program: +@racketblock[((λ (x) (+ x 1)) + 17)] + +@exercise[] + +Use @racket[redex-match] to extract the range portion +of the type +@racket[(→ num (→ num num))]. + + @exercise[] Redex's pattern language supports ambiguity through non-terminals, @@ -223,6 +241,19 @@ then you'd expect one match for 1 & 2, one match for 2 & 3, and one match for 3 In general, this pattern should produce n matches when there are n+1 expressions in the sequence. +To test your solution use @racket[redex-match] like this: +@racketblock[(redex-match + L + (code:comment @#,t{your solution goes here}) + (term (1 2 3 4)))] +where you expect a result like this +@racketblock[(list + (match (list (bind 'e_1 1) (bind 'e_2 2))) + (match (list (bind 'e_1 2) (bind 'e_2 3))) + (match (list (bind 'e_1 3) (bind 'e_2 4))))] +but possibly with more pattern variables in the resulting +match. + @amb/test[(redex-match L (e_1 ... e_2 e_3 e_4 ...)