Advertisement
morty0505

Untitled

Oct 16th, 2016
2,877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun robPoint () =
  2.     let
  3.         val maxX = ref ~1
  4.         val maxY = ref ~1
  5.         val x = ref ~1
  6.         val y = ref ~1
  7.  
  8.         fun move(i,j) =
  9.             (
  10.             x := !x + i;
  11.             y := !y + j;
  12.             if !x <= !maxX andalso !y <= !maxY andalso !x >= 0 andalso !y >= 0 then
  13.                 (i,j)
  14.             else raise RobolOutOfGrid
  15.             )
  16.  
  17.         fun start(i,j) =
  18.             (x := i ; y := j;(i,j))
  19.  
  20.         fun get(i,j) =
  21.             (!x,!y)
  22.  
  23.         fun setMax(i,j) =
  24.             (maxX := i ; maxY := j;(i,j))
  25.  
  26.         fun dispatch("move") = move
  27.         |   dispatch("start") = start
  28.         |   dispatch("setMax") = setMax
  29.         |   dispatch(_) = get
  30.  
  31.     in
  32.         dispatch
  33.     end;
  34.  
  35. val robolPoint = robPoint();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement