Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build and Deploy
on:
- push
- repository_dispatch:
types: [slides-updated]
# - repository_dispatch:
# types: [slides-updated]

jobs:
build:
Expand All @@ -11,12 +11,12 @@ jobs:
GH_TOKEN: ${{ github.token }}
steps:
# Show payload only for repository_dispatch
- name: Show dispatch payload
if: ${{ github.event_name == 'repository_dispatch' }}
run: |
echo "Event type: ${{ github.event.action || 'N/A' }}"
echo "Client payload (JSON):"
echo '${{ toJson(github.event.client_payload) }}'
# - name: Show dispatch payload
# if: ${{ github.event_name == 'repository_dispatch' }}
# run: |
# echo "Event type: ${{ github.event.action || 'N/A' }}"
# echo "Client payload (JSON):"
# echo '${{ toJson(github.event.client_payload) }}'
- name: Set timezone
uses: szenius/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion www/assignments.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@include-section{assignments/6.scrbl}
@include-section{assignments/7.scrbl}
@include-section{assignments/8.scrbl}
@include-section{assignments/9.scrbl}
@;include-section{assignments/9.scrbl}
@;include-section{assignments/10.scrbl}


Expand Down
145 changes: 142 additions & 3 deletions www/assignments/8.scrbl
Original file line number Diff line number Diff line change
@@ -1,9 +1,148 @@
#lang scribble/manual
@(require "../defns.rkt")
@title[#:tag "Assignment 8" #:style 'unnumbered]{Assignment 8: Functions with default arguments}
@title[#:tag "Assignment 8" #:style 'unnumbered]{Assignment 8: Patterns}

@(require (for-label a86 (except-in racket ...)))
@(require (for-label (except-in racket ...)))
@(require "../notes/ev.rkt"
"../notes/utils.rkt")

@bold{Due: @assign-deadline[8]}

Details of this assignment will be released later in the semester.
@(ev '(require knock-plus))

The goal of this assignment is to extend a compiler with new pattern
matching forms for matching lists, vectors, and predicates.

You are given a file @tt{knock-plus.zip} on ELMS with a starter
compiler similar to the @seclink["Knock"]{Knock} language we studied
in class. You are tasked with:

@itemlist[

@item{implementing the @tt{list} pattern,}

@item{implementing the @tt{vector} pattern, and}

@item{implementing the @tt{?} pattern.}
]

The following files have already been updated for you @bold{and should
not be changed by you}:

@itemlist[ @item{@tt{ast.rkt}}
@item{@tt{parse.rkt}}
@item{@tt{interp.rkt}}
@item{@tt{interp-prim.rkt}}
@item{@tt{compile-op.rkt}}
]

So you will only need to modify:
@itemlist[
@item{@tt{compile.rkt}}
]
to correctly implement the new features. These features are described below.

As a convenience, two new n-ary primitives have been added (and fully
implemented): @racket[list] and @racket[vector]. The @racket[list]
primitive takes any number of arguments and produces a list containing
the arguments as elements; the @racket[vector] primitive does the
same, but constructs a vector.

@ex[
(list)
(list 1 2 3)
(list 1 #t #\c)
(vector)
(vector 1 2 3)
(vector 1 #t #\c)]

These are not directly useful in implementing the patterns above, but
do make it easier to write examples and tests.

@section[#:tag-prefix "a8-" #:style 'unnumbered #:tag "list"]{List patterns}

The @racket[(list _p1 ... _pn)] pattern matches a list of elements. The
pattern matches a list with as many elements as there are patterns
@racket[_p1] through @racket[_pn] and each element must match the
respective pattern.


@ex[
(match (list)
[(list) #t]
[_ #f])
(match (list 1 2 3)
[(list x y z) x])
(match (list (list 1) (list 2))
[(list (list x) (list 2)) x])
]

@section[#:tag-prefix "a8-" #:style 'unnumbered #:tag "vector"]{Vector patterns}

The @racket[(vector _p1 ... _pn)] pattern matches a vector of elements. The
pattern matches a vector with as many elements as there are patterns
@racket[_p1] through @racket[_pn] and each element must match the
respective pattern.


@ex[
(match (vector)
[(vector) #t]
[_ #f])
(match (vector 1 2 3)
[(vector x y z) x])
(match (vector (vector 1) (vector 2))
[(vector (vector x) (vector 2)) x])
]

@section[#:tag-prefix "a8-" #:style 'unnumbered #:tag "vector"]{Predicate patterns}

The @racket[(? _f)] pattern matches any value for which the predicate
@racket[_f] returns a true value (any value other than @racket[#f])
when applied to the value being matched. In Knock+, @racket[_f] must be
the name of a user defined function.

@ex[
(define (is-eight? x) (= x 8))
(define (id x) x)

(match 8
[(? is-eight?) #t]
[_ #f])
(match (vector 1 2 3)
[(and (? id) x) x])
(match 16
[(? is-eight?) #t]
[_ #f])
]

@section[#:tag-prefix "a8-" #:style 'unnumbered]{Representing the syntax of patterns}

The AST of patterns is extended as follows:

@#reader scribble/comment-reader
(racketblock
;; type Pat = ...
;; | (List [Listof Pat])
;; | (Vect [Listof Pat])
;; | (Pred Id)
)

The parser includes a @racket[parse-pattern] function that parses a
single pattern:

@ex[
(parse-pattern 'x)
(parse-pattern '(cons x y))
(parse-pattern '(list x y z))
(parse-pattern '(vector x y z))
(parse-pattern '(? f?))
]



@section[#:tag-prefix "a8-" #:style 'unnumbered]{Submitting}

Submit a zip file containing your work to Gradescope. Use @tt{make
submit.zip} from within the @tt{knock-plus} directory to create a zip
file with the proper structure.
4 changes: 2 additions & 2 deletions www/defns.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"Thursday, October 23, 11:59PM"
"Tuesday, November 4, 11:59PM"
"Tuesday, November 11, 11:59PM"
"Thursday, November 20, 11:59PM"
"Thursday, December 4, 11:59PM")
"Tuesday, December 9, 11:59PM"
#;"Thursday, December 4, 11:59PM")
(sub1 i)))

(define office-hours
Expand Down