Bind & Interpretation of AppC in AAQZ 4

Table of Contents

1. Bind

adding new expressoion

 <expr>::= ...
        | {bind <clause> ... <expr>}

<clause>::= [<id> = <expr>]

1 {bind [x = 17] {* 2 x}}

2 {bind [add 1 = {(x) => {+ x 1}}] …}

if we already have the langauge that supports this feature we can just make it parse into the exisiting abstract syntax.

WE DONT NEED A BINDC

So all we have to do is add a clause to the parser…

{bind [name = val] body} --> {{(name) => body} val}

Bind is just a AppC & LamC.

1.1. Syntatic Sugar

Bind is an example of syntatic sugar.

Syntatic Sugar: syntax that you may prefer but the rest of the PL needs to know nothing about.

Desugaring: moving the sugared code into stuff the program has and can use.

Example:

{bind [x=5] [x=7] {+ x y}} -desugar-> {{(x y) => {+ x y}} 5 7} -parse-> (AppC (LamC ’(x y) (AppC (IdC ’+) (list (IdC ’x) (IdC ’y))))….

2. Interping an AppC in AAQZ 4

common mistakes

  • once the first clov is interpreted naming the match for the clov the same as current env
  • Extending the environment to the wrong CloV

{bind [f = {(x) => {(x) => {+ x y}}}] {{f 3} 7}}

func = {f 3}

arg = 7

  1. Interp func in the current envionment
    • CloV
      • Param : Y
      • body : {x + y}
      • env : x -> (NumV 3)
      • stuff always in env: + - * / true false
  2. Interp the the arg interpret arg in current environment
  3. Extend the closures env with new bindings from closures params to interpet args.
    • Extension of the previous environment with new things
      • y -> 7, x ->> 3, + -> …
  4. Interp the closure body with the new extended environment
    • books approach uses cons to extend the enviornments on the top

Date: 2024-10-21 Mon 00:00

Author: Anthony Rossi

Created: 2024-10-21 Mon 16:58