User loginNavigation |
New methods for functional style programming in Dao, any comments or suggestions?Dao (posted here before) was not initially designed to be a functional programming language, but with time some functional features were added to the language. And recently I designed and implemented (for the next release) several built-in methods to increase its support for functional style programming. These methods are documented here: http://www.daovm.net/space/dao/thread/137. It is slightly similar to that of Ruby with a few distinctive feature. Basically, it looks like something like this, RESULT = METHOD( PARAMETER ) -> |VARIABLE| { EXPRESSION } Here PARAMETER can be one or more list or array (almost all these methods are applicable to numeric arrays), or other data types depending on METHOD. |VARIABLE| is to declare variables associated with list/array items or indices etc. |VARIABLE| can also be omitted so that default parameter names will be used. EXPRESSION is the inlined function to be applied, normal statements (except return statement) can also be used, in this case, the statement code block must be separated from the EXPRESSION by "return" key word. EXPRESSION can actually be multiple expressions separated by comma(s) in method such as map(), which will return a list of tuples in such cases. Function composition is simply supported by allowing one or more ->|...|{...} constructs to append one after another. In such cases, |VARIABLE| can be used to declare variables referring the results of EXPRESSION in the previous ->|...|{...} construct. A simple example: a = { 1, 2, 3 } b = { 7, 8, 9 } zip_ab = map( a, b ) -> |u,v| { u, v } zip_ab = map( a, b ) -> { x, y } zip_ab = select( a, b ) -> { 1 } c = map( a, b ) -> |x,y| { x-y, x+y } -> |u,v| { u*v } d = map( a ) -> |x| { u = 10*x; v = x+10; if( u < v ) u += v; return u*v } e = unfold( 5 ) -> |x| { while x > 0 return x - 1 } e = unfold( 5 ) -> |x| { stdio.println(x) while x > 0 return x - 1 }
Your comments, suggestions or opinions are welcome, By Limin Fu at 2009-08-10 18:10 | LtU Forum | previous forum topic | next forum topic | other blogs | 3803 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 19 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago