Diff
Not logged in

Differences From Artifact [70846dfa5638c8e7]:

To Artifact [5b490c90826e242f]:


43 43 ctx.add("/", new FunValue(delegate Value(immutable LexPosition pos, Value[] args){ 44 44 if( args.length != 2 ) 45 45 throw new PolemyRuntimeException("/ takes two arguments!! ["~to!string(pos)~"]"); 46 46 if( auto x = cast(IntValue)args[0] ) 47 47 if( auto y = cast(IntValue)args[1] ) 48 48 return new IntValue(x.data/y.data); 49 49 throw new PolemyRuntimeException("cannot add non-integers ["~to!string(pos)~"]"); 50 + })); 51 + ctx.add("<", new FunValue(delegate Value(immutable LexPosition pos, Value[] args){ 52 + if( args.length != 2 ) 53 + throw new PolemyRuntimeException("< takes two arguments!! ["~to!string(pos)~"]"); 54 + if( auto x = cast(IntValue)args[0] ) 55 + if( auto y = cast(IntValue)args[1] ) 56 + return new IntValue(BigInt(to!int(x.data < y.data))); 57 + throw new PolemyRuntimeException("cannot add non-integers ["~to!string(pos)~"]"); 58 + })); 59 + ctx.add(">", new FunValue(delegate Value(immutable LexPosition pos, Value[] args){ 60 + if( args.length != 2 ) 61 + throw new PolemyRuntimeException("> takes two arguments!! ["~to!string(pos)~"]"); 62 + if( auto x = cast(IntValue)args[0] ) 63 + if( auto y = cast(IntValue)args[1] ) 64 + return new IntValue(BigInt(to!int(x.data>y.data))); 65 + throw new PolemyRuntimeException("cannot add non-integers ["~to!string(pos)~"]"); 50 66 })); 51 67 ctx.add("print", new FunValue(delegate Value(immutable LexPosition pos, Value[] args){ 52 68 foreach(a; args) 53 69 write(a); 54 70 writeln(""); 55 71 return new UndefinedValue; 56 72 })); ................................................................................ 201 217 evalString(`var fac = fun(x){ 202 218 if(x) 203 219 { x*fac(x-1); } 204 220 else 205 221 { 1; }; 206 222 }; 207 223 print(fac(10));`); 224 + evalString(`var fib = fun(x){ 225 + if(x<2) 226 + { 1; } 227 + else 228 + { fib(x-1) + fib(x-2); }; 229 + }; 230 + print(fib(10));`); 208 231 }