From be1d4b5da9c7e8b36b355ef0df58cee94543b74c Mon Sep 17 00:00:00 2001
From: tomsmeding <tom.smeding@gmail.com>
Date: Sun, 20 Nov 2016 22:41:42 +0100
Subject: Add `init` and `cons`

---
 prelude.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'prelude.cpp')

diff --git a/prelude.cpp b/prelude.cpp
index 8fc9d8a..7d9b4c3 100644
--- a/prelude.cpp
+++ b/prelude.cpp
@@ -19,7 +19,8 @@ const AST afterBootstrap=AST(R"RAW(
 	(def 'print (. putstr repr))
 	(def '$ \f \x (f x))
 	(def 'if \c \t \f (__if c (() t) (() f)))
-	(def 'last \l (if (nil (tail l)) (head l) (last (tail l)))))
+	(def 'last \l (if (nil (tail l)) (head l) (last (tail l))))
+	(def 'init \l (if (nil (tail l)) '() (cons (head l) (init (tail l))))))
 )RAW");
 
 static AST dofunction(const AST&);
@@ -81,6 +82,13 @@ public:
 				return res;
 			}));
 
+		intoEnv.define("cons",checkedHook("cons",{},{AST::Type::tuple},
+			[](Environment&,const AST &arg1,const AST &arg2) -> AST {
+				AST res(arg2);
+				res.terms.insert(res.terms.begin(),arg1);
+				return res;
+			}));
+
 		intoEnv.define("nil",checkedHook("nil",{AST::Type::tuple},
 			[](Environment&,const AST &arg) -> AST {
 				return AST::makeNumber(arg.terms.size()==0);
-- 
cgit v1.2.3-70-g09d2