{"size": 2333, "ext": "scrbl", "max_stars_repo_path": "redex-doc/redex/scribblings/long-tut/lab-mon-aft.scrbl", "max_stars_repo_name": "LiberalArtist/redex", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "redex-doc/redex/scribblings/long-tut/lab-mon-aft.scrbl", "max_issues_repo_name": "LiberalArtist/redex", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "redex-doc/redex/scribblings/long-tut/lab-mon-aft.scrbl", "max_forks_repo_name": "LiberalArtist/redex", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 10, "max_issues_count": 15, "max_forks_count": null, "avg_line_length": 24.3020833333, "max_line_length": 102, "alphanum_fraction": 0.6579511359}
#lang scribble/manual

@(require "shared.rkt")

@; ---------------------------------------------------------------------------------------------------
@title[#:tag "lab-mon-aft"]{@bold{Lab} Designing Metafunctions}

@goals[
@item{developing meta-functions}
@item{discovering Redex patterns}
]

@common[]

@section[#:tag "lma" #:style 'unnumbered]{Exercises}

@exercise["ex:bv"]{Design @racket[bv]. The metafunction determines the
bound variables in a @racket[Lambda] expression. A variable @racket[x] is 
@defterm{bound in @racket[e_Lambda]} if @racket[x] occurs in a
@racket[lambda]-parameter list in e_@racket[Lambda].}

@exercise["ex:lookup"]{Design @racket[lookup]. The metafunction consumes a
variable and an @tech{environment}. It determines the leftmost expression
associated with the variable; otherwise it produces @racket[#false].

Here is the definition of @deftech{environment}: 
@;%
@(begin
#reader scribble/comment-reader
(racketblock
(define-extended-language Env Lambda
  (e ::= .... natural)
  (env ::= ((x e) ...)))
))
@;%
 The language extension also adds numbers of the sub-language of
 expressions. 

Before you get started, make sure you can create examples of
@tech{environment}s and confirm their well-formedness.}

@exercise["ex:let"]{Develop the metafunction @racket[let], which extends
 the language with a notational shorthand, also known as syntactic sugar. 

 Once you have this metafunction, you can write expressions such as 
@;%
@(begin
#reader scribble/comment-reader
(racketblock
(term 
  (let ((x (lambda (a b c) a))
        (y (lambda (x) x)))
    (x y y y)))
))
@;%
 Like Racket's @racket[let], the function elaborates surface syntax into
 core syntax:
@;%
@(begin
#reader scribble/comment-reader
(racketblock
(term 
  ((lambda (x y) (x y y y))
   (lambda (a b c) a)
   (lambda (x) x)))
))
@;%

 Since this elaboration happens as the term is constructed, all other
 metafunctions work as expected on this extended syntax. For example,
@;%
@(begin
#reader scribble/comment-reader
(racketblock
(term 
 (fv 
  (let ((x (lambda (a b c) a))
        (y (lambda (x) x)))
    (x y y y))))
))
@;%
 or 
@;%
@(begin
#reader scribble/comment-reader
(racketblock
(term 
 (bv
  (let ((x (lambda (a b c) a))
        (y (lambda (x) x)))
    (x y y y))))
))
@;%
 produces the expected results. What are those?}

