This is a simple example about using functions as parameters. function reduce(f: function(Number,Number):Number, list: Number[], nilArg: Number):Number { if( list == [] ) then nilArg else f( list[0], reduce(f, list[x|indexof x > 0], nilArg)) } function sum( x: Number, y: Number ): Number { x + y } function product( x: Number, y: Number ): Number {x * y } def list : Number[] = [1,2,3,4]; function p( s: String ) { println( s ); } p("# sum : {reduce(sum,list,0)}"); p("# product : {reduce(product,list,1)}");
Attributes | Values |
---|
rdfs:label
| - Functional Programming
- Functional programming
|
rdfs:comment
| - This is a simple example about using functions as parameters. function reduce(f: function(Number,Number):Number, list: Number[], nilArg: Number):Number { if( list == [] ) then nilArg else f( list[0], reduce(f, list[x|indexof x > 0], nilArg)) } function sum( x: Number, y: Number ): Number { x + y } function product( x: Number, y: Number ): Number {x * y } def list : Number[] = [1,2,3,4]; function p( s: String ) { println( s ); } p("# sum : {reduce(sum,list,0)}"); p("# product : {reduce(product,list,1)}");
- 2 курса лекций по функциональному программированию
* Александр Кубенский
* Евгений Кирпичёв Category theory foundations
|
sameAs
| |
dcterms:subject
| |
dbkwik:encyclopedi...iPageUsesTemplate
| |
dbkwik:nupedia/pro...iPageUsesTemplate
| |
abstract
| - This is a simple example about using functions as parameters. function reduce(f: function(Number,Number):Number, list: Number[], nilArg: Number):Number { if( list == [] ) then nilArg else f( list[0], reduce(f, list[x|indexof x > 0], nilArg)) } function sum( x: Number, y: Number ): Number { x + y } function product( x: Number, y: Number ): Number {x * y } def list : Number[] = [1,2,3,4]; function p( s: String ) { println( s ); } p("# sum : {reduce(sum,list,0)}"); p("# product : {reduce(product,list,1)}");
- 2 курса лекций по функциональному программированию
* Александр Кубенский
* Евгений Кирпичёв Category theory foundations
|