Commit d6f70f4a authored by Marc Coiffier's avatar Marc Coiffier
Browse files

Make list creation more efficient in concatenative languages, by building the...

Make list creation more efficient in concatenative languages, by building the result in order instead of building it in reverse, then reversing it again
parent a4ee7b12
......@@ -95,10 +95,10 @@ execBuiltin runExtra onComment = go
(val:StackSymbol var:tl) -> do dict =~ insert var val ; stack =- tl
_ -> return ()
go Builtin_ListBegin = stack =~ (StackBuiltin Builtin_ListBegin:)
go Builtin_ListEnd = stack =~ \st -> let (h,_:t) = break (\x -> case x of
StackBuiltin Builtin_ListBegin -> True
_ -> False) st
in StackList (reverse h):t
go Builtin_ListEnd = stack =~ \st -> let ex acc (StackBuiltin Builtin_ListBegin:t) = (acc,t)
ex acc (h:t) = ex (h:acc) t
ex acc [] = (acc,[])
in let (h,t) = ex [] st in StackList h:t
go Builtin_Stack = stack =~ \x -> StackList x:x
go Builtin_Clear = stack =- []
go Builtin_Pick = stack =~ \st -> case st of StackInt i:StackInt n:t | i<n, x:t' <- drop i t -> x:drop (n-i-1) t'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment