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
- branch=trunk inherited from [f65680e1d2]
- sym-trunk inherited from [f65680e1d2]
Changes
Modified polemy/eval.d from [70846dfa5638c8e7] to [5b490c90826e242f].
43 ctx.add("/", new FunValue(delegate Value(immutable LexPosition pos, Valu 43 ctx.add("/", new FunValue(delegate Value(immutable LexPosition pos, Valu 44 if( args.length != 2 ) 44 if( args.length != 2 ) 45 throw new PolemyRuntimeException("/ takes two arguments! 45 throw new PolemyRuntimeException("/ takes two arguments! 46 if( auto x = cast(IntValue)args[0] ) 46 if( auto x = cast(IntValue)args[0] ) 47 if( auto y = cast(IntValue)args[1] ) 47 if( auto y = cast(IntValue)args[1] ) 48 return new IntValue(x.data/y.data); 48 return new IntValue(x.data/y.data); 49 throw new PolemyRuntimeException("cannot add non-integers ["~to! 49 throw new PolemyRuntimeException("cannot add non-integers ["~to! > 50 })); > 51 ctx.add("<", new FunValue(delegate Value(immutable LexPosition pos, Valu > 52 if( args.length != 2 ) > 53 throw new PolemyRuntimeException("< takes two arguments! > 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.dat > 57 throw new PolemyRuntimeException("cannot add non-integers ["~to! > 58 })); > 59 ctx.add(">", new FunValue(delegate Value(immutable LexPosition pos, Valu > 60 if( args.length != 2 ) > 61 throw new PolemyRuntimeException("> takes two arguments! > 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! 50 })); 66 })); 51 ctx.add("print", new FunValue(delegate Value(immutable LexPosition pos, 67 ctx.add("print", new FunValue(delegate Value(immutable LexPosition pos, 52 foreach(a; args) 68 foreach(a; args) 53 write(a); 69 write(a); 54 writeln(""); 70 writeln(""); 55 return new UndefinedValue; 71 return new UndefinedValue; 56 })); 72 })); ................................................................................................................................................................................ 201 evalString(`var fac = fun(x){ 217 evalString(`var fac = fun(x){ 202 if(x) 218 if(x) 203 { x*fac(x-1); } 219 { x*fac(x-1); } 204 else 220 else 205 { 1; }; 221 { 1; }; 206 }; 222 }; 207 print(fac(10));`); 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 }