diff options
| -rw-r--r-- | prelude.cpp | 22 | 
1 files changed, 11 insertions, 11 deletions
diff --git a/prelude.cpp b/prelude.cpp index 7d9b4c3..f9cf6ff 100644 --- a/prelude.cpp +++ b/prelude.cpp @@ -18,7 +18,6 @@ const AST afterBootstrap=AST(R"RAW(  	(def 'const \x \y x)  	(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 'init \l (if (nil (tail l)) '() (cons (head l) (init (tail l))))))  )RAW"); @@ -31,6 +30,11 @@ static AST dofunction(const AST&){  	return doNative;  } + +const AST chooseFirstLambda=AST::makeLambda("",AST::makeLambda("",AST::makeIndex(2))); +const AST chooseSecondLambda=AST::makeLambda("",AST::makeLambda("",AST::makeIndex(1))); + +  class PreludeInit{  public:  	PreludeInit(Environment &intoEnv){ @@ -99,17 +103,13 @@ public:  				return AST::makeNumber(arg.numval==0);  			})); -		intoEnv.define("__if",checkedHook("__if",{AST::Type::number},{AST::Type::tuple},{AST::Type::tuple}, -			[](Environment&,const AST &arg1,const AST &arg2,const AST &arg3) -> AST { -				if(arg2.terms.size()!=2||arg3.terms.size()!=2){ -					throw FormError("Then and else arguments to '__if' should be 2-tuples with value in second element"); -				} -				const AST &choice=arg1.numval!=0?arg2:arg3; -				AST res=choice.terms[1]; -				if(choice.quoted){ -					res.quoted=true; +		intoEnv.define("if",checkedHook("if",{AST::Type::number}, +			[](Environment&,const AST &arg) -> AST { +				if(arg.numval!=0){ +					return chooseFirstLambda; +				} else { +					return chooseSecondLambda;  				} -				return res;  			}));  		intoEnv.define("+",checkedHook("+",{AST::Type::number,AST::Type::string},  | 
