Check-in [172a537bea]
Not logged in
Overview
SHA1 Hash:172a537bea5aff0633a2e02ebcbca3376cd4684c
Date: 2010-11-08 01:33:34
User: kinaba
Comment:operator < and > for integers, for writing Fibonacci function.
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified polemy/eval.d from [70846dfa5638c8e7] to [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 }