AAQZ6 Specification
Table of Contents
1. AAQZ6
Transition from AAQZ4 to AAQZ6, with additional features and mutations.
1.1. Environment and Store Model
- env : name -> location
- store : location -> value
- Implemented as a Racket vector
1.2. Enhancements to Add
- Binding mutations (Parser)
- Structural mutations (PrimV’s)
- Mutable Arrays (Parser)
1.3. Binding Mutations
New syntax:
- Rebind: `{x := v}` - rebinds `x` to `v`.
- Locate `x` in the environment and update its corresponding location in the store with the result of interpreting `v`.
Example:
{bind [x = 10] [y = 20] ;; Swap x and y {bind [tmp = x] {seq {x := y} {y := tmp}}}}
Resulting Environment (env):
- x => 0
- y => 1
- tmp => 2
Resulting Store (store):
Location | Value |
---|---|
0 | (NumV 10) |
1 | (NumV 20) |
After Execution:
Location | Value |
---|---|
0 | (NumV 20) |
1 | (NumV 10) |
Note: Mutations only affect the store; the environment mapping remains unchanged.
1.4. Recursive Functions with Mutations
Example:
{bind [fact = -17] {bind [f = {(n) => {if {<= n 0} 1 {* n {fact {- n 1}}}}}] {seq {fact := f} {fact 5}}}}
Result: `ClosV` loop with an environment pointing to itself.
1.5. Arrays
New syntax and types (all as PrimV):
- Create Array: `{array e …}`
- Initializes a new array with the specified values.
- Fixed Array: `{makearray size value}`
- Creates an array of the given `size`, filled with `value`.
- Array Reference: `{aref array index}`
- Equivalent to `array[index]`.
- Array Set: `{aset array index value}`
- Equivalent to `array[index] = value`.
2. AAQZ6
AAQZ4 -> AAQZ6
env : name -> location
store : location -> value
- implemented as a racket vector
stuff to add
- Add binding mutations(parser)
- Add structural mutations(PrimV’s)
- Add Arrays(Mutible)(parser)
2.1. Binding mutations
new syntax!
Rebind
{x := v} - rebind x to be v.
- go to where x is and change it to the value from interpreting v
Example:
{bind [x = 10] [y = 20] ;;swap x and y {bind [tmp = x] {seq {x := y} {y := tmp}}}}
Env
x => 0 y => 1 tmp => 2
store
0 | 1 | … |
----------
(NumV 10) | (NumV 20) |
after the program run…
0 | 1 | … |
--------
(NumV 20) | (NumV 10) |
mutation does not change the enviornment but instead, what is at the location in the store
Recursion with mutations
{bind [fact = -17] {bind [f = {(n) => {if {<= n 0} 1 {* n {fact {- n 1}}}}}] {seq {fact := f} {fact 5}}}}
with this the we get a looped ClosV that contains an enviornment which points to itself.
2.2. Arrays
more syntax! (All of these are going to be PrimV) and new value type
{array e …}
- make a new array with given values
{makearray size value}
- make a new array of the given size of filled with the value.
{aref array index}
- “array[index]”
{aset array index value}
- “array[index] = value”