progs/bf/bfi.sc
changeset 742 b5b5583a3a08
parent 738 084e2843f478
child 743 6acabeecdf75
equal deleted inserted replaced
741:e66bd5c563eb 742:b5b5583a3a08
     5 //
     5 //
     6 //  amm bfi.sc <<bf_program.bf>>
     6 //  amm bfi.sc <<bf_program.bf>>
     7 //
     7 //
     8 
     8 
     9 
     9 
    10 import scala.util._
    10 // BF memory is represented as a Map
    11 
       
    12 // BF memory as a map
       
    13 type Mem = Map[Int, Int]
    11 type Mem = Map[Int, Int]
    14 
    12 
    15 // reading and writing BF memory
    13 // safe reading and writing of BF memory
    16 def sread(mem: Mem, mp: Int) : Int = 
    14 def sread(mem: Mem, mp: Int) : Int = 
    17   mem.getOrElse(mp, 0)
    15   mem.getOrElse(mp, 0)
    18 
    16 
    19 def write(mem: Mem, mp: Int, v: Int) : Mem =
    17 def write(mem: Mem, mp: Int, v: Int) : Mem =
    20   mem.updated(mp, v)
    18   mem.updated(mp, v)