remove unneccesary tape updates and use $
[bf.git] / cleanbf.icl
index be3c422..57064c5 100644 (file)
@@ -5,6 +5,8 @@ import System.CommandLine
 import Data.Error
 import System.File
 
+from Data.Func import $
+
 import _SystemArray
 import StdEnv
 
@@ -15,7 +17,7 @@ TAPESIZE :== 1024
 bf :: *BFState -> Either *BFState *BFState
 bf st=:{prog,pc,tc,tape,cs}
 | st.pc == size st.prog = Left st
-= let (b, tape`) = uselect tape tc in Right (case select prog pc of
+= let (b, tape`) = uselect tape tc in Right case select prog pc of
        '<' = {st & pc=pc+1, tape=tape`, tc=tc-1}
        '>' = {st & pc=pc+1, tape=tape`, tc=tc+1}
        '+' = {st & pc=pc+1, tape=update tape` tc (b+1)}
@@ -25,14 +27,14 @@ bf st=:{prog,pc,tc,tape,cs}
                in {st & pc=pc+1, tape=update tape` tc (toInt c), io=io}
        '[' = let st` = {st & cs=[pc:cs], tape=tape`, pc=pc+1} in if (b == 0)
                        {st` & pc=1+(while (\pc`->select prog pc` <> ']') ((+) 1) pc)} st`
-       ']' = {st & tape=tape`, pc=hd cs, cs=tl cs}
-       _ = {st & pc=pc+1})
+       ']' = {st & pc=hd cs, cs=tl cs}
+       _ = {st & pc=pc+1}
 
 f :: (.a -> (Either .a .a)) -> .(.a -> .a)
 f g = (either id (f g)) o g
 
 mkState :: !*File String -> *BFState
-mkState f s = {pc=0,tc=0,io=f,cs=[],tape={0\\_<-[0..1024]},prog=s}
+mkState f s = {pc=0,tc=0,io=f,cs=[],tape={0\\_<-[0..TAPESIZE]},prog=s}
 
 Start w
 # ([_:p], w) = getCommandLine w