testing3/bf.scala
changeset 154 e7f8e3d2e09a
parent 153 316f9c6cc2ff
child 160 250e1d7df9ff
equal deleted inserted replaced
153:316f9c6cc2ff 154:e7f8e3d2e09a
     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