testing3/bf.scala
changeset 154 39c6b93718f0
parent 153 4383809c176a
child 160 863feeb5c760
equal deleted inserted replaced
153:4383809c176a 154:39c6b93718f0
     6 type Mem = Map[Int, Int]
     6 type Mem = Map[Int, Int]
     7 
     7 
     8 // (2a) Complete the functions for safely reading  
     8 // (2a) Complete the functions for safely reading  
     9 // and writing brainf*** memory. Safely read should
     9 // and writing brainf*** memory. Safely read should
    10 // Return the value stored in the Map for a given memory
    10 // Return the value stored in the Map for a given memory
    11 // pointer, if it exists; otherwise Returns 0. The
    11 // pointer, if it exists; otherwise it Returns 0. The
    12 // writing function generates a new Map with the
    12 // writing function generates a new Map with the
    13 // same data, except at the given memory pointer the
    13 // same data, except at the given memory pointer the
    14 // a value v is stored.
    14 // value v is stored.
    15 
    15 
    16 
    16 
    17 def sread(mem: Mem, mp: Int) : Int = 
    17 def sread(mem: Mem, mp: Int) : Int = 
    18   mem.getOrElse(mp, 0)
    18   mem.getOrElse(mp, 0)
    19 
    19