Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

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

Define a 'cons' builtin for CaPriCon (and other concatenative languages)

parent c1df9304
......@@ -67,7 +67,7 @@ data StackBuiltin b = Builtin_ListBegin | Builtin_ListEnd
| Builtin_Pop | Builtin_PopN
| Builtin_Dup | Builtin_DupN
| Builtin_Swap | Builtin_SwapN
| Builtin_Range | Builtin_Each
| Builtin_Range | Builtin_Each | Builtin_Cons
| Builtin_Add | Builtin_Sub | Builtin_Mul | Builtin_Div | Builtin_Mod | Builtin_Sign
| Builtin_DeRef | Builtin_Def
| Builtin_Exec
......@@ -175,6 +175,9 @@ execBuiltinImpl runExtra onComment = go
st -> st
go Builtin_Dup = stack =~ \st -> case st of x:t -> x:x:t ; _ -> st
go Builtin_DupN = stack =~ \st -> case st of StackInt n:t | x:_ <- drop n t -> x:t ; _ -> st
go Builtin_Cons = stack =~ \case
x:StackList l:st' -> StackList (x:l):st'
st -> st
go Builtin_Range = stack =~ \st -> case st of StackInt n:t -> StackList [StackInt i | i <- [0..n-1]]:t ; _ -> st
go Builtin_Each = do
st <- get
......
......@@ -451,6 +451,7 @@ cocDict version getResource getBResource writeResource writeBResource =
("list/each" , Builtin_Each ),
("list/range" , Builtin_Range ),
("list/cons" , Builtin_Cons ),
("dict/vocabulary" , Builtin_CurrentDict ),
("dict/empty" , Builtin_Empty ),
......
Markdown is supported
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