Overview
SHA1 Hash: | da7559b74430201497f24ead85b618674a822195 |
---|---|
Date: | 2010-11-22 01:05:20 |
User: | kinaba |
Comment: | fizzbuzz sample changed |
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 sample/fizzbuzz.pmy from [d3f621f8aabb3e95] to [6b6d7ff7af65edf2].
1 1 # 2 2 # Not at all a good example of the usage of layers, but anyway... 3 3 # 4 -# after implementing layered parameters, this may be improved. 5 -# (though still not a good example...) 6 -# 7 4 8 -@ 3 print(x) { @v(print("Fizz")) }; 9 -@ 5 print(x) { @v(print("Buzz")) }; 10 -@15 print(x) { @v(print("FizzBuzz")) }; 5 +@@3(x){x}; 6 +@@5(x){x}; 7 +@@15(x){x}; 8 +def incr(x) { x+1 }; 9 +@ 3 incr(x) {@value( if(@ 3(x)+1< 3){@ 3(x)+1}else{0} )}; 10 +@ 5 incr(x) {@value( if(@ 5(x)+1< 5){@ 5(x)+1}else{0} )}; 11 +@15 incr(x) {@value( if(@15(x)+1<15){@15(x)+1}else{0} )}; 11 12 12 -def fb(n, q3, q5, q15) { 13 - if( q15 < 1 ) { 14 - @15(print) 15 - } else { 16 - if( q5 < 1 ) { 17 - @5(print) 18 - } else { 19 - if( q3 < 1 ) { 20 - @3(print) 21 - } else { 22 - @v(print) 23 - } 24 - } 25 - }(n); 26 - let q3 = q3+1; 27 - let q5 = q5+1; 28 - let q15 = q15+1; 29 - 30 - fb( 31 - n+1, 32 - if(q3<3){q3}else{0}, 33 - if(q5<5){q5}else{0}, 34 - if(q15<15){q15}else{0} 35 - ) 13 +def fb(n @value @3 @5 @15) { 14 + print( 15 + if( @15(n) ) { if( @5(n) ) { if( @3(n) ) { n } else { "Fizz" } } else { "Buzz" } } else { "FizzBuzz" } 16 + ); 17 + fb(incr(n)) 36 18 }; 37 19 38 -fb(0,0,0,0) 20 +fb(0)
Modified sample/type.pmy from [ed44c7901d3c5853] to [b35cfd66e862f7bf].
1 1 @@type = fun(x){ 2 2 if( _isint(x) ) { "int" } 3 3 else { if( _isstr(x) ) { "str" } 4 - else { if( _isfun(x) ) { x } 5 4 else { if( _isundefined(x) ) { "undefined" } 6 - else { "any" }}}} 5 + else { "any" }}} 7 6 }; 8 7 9 8 def binop(a,b,c) { 10 9 fun(x,y){@value( 11 10 if( @type(x)=="undefined" || @type(y)=="undefined" ) { "undefined" } else { 12 11 if( @type(x)==a && @type(y)==b ) { c } else { "error" } 13 12 }