User loginNavigation |
Unimperative Programming Language - Teaser
The following is from my latest project which is a foray into functional programming. Any comments or suggestions?
The Unimperative Programming Languageby Christopher DigginsIntroductionUnimperative is a simple programming language, which supports a mix of procedural programming and functional programming. In Unimperative the primary data type is a function. The sequence of evaluation in Unimperative matters somewhat, and function parameters are evaluated left to right. Unimperative has a surprise twist, which I will save for the end Comparing to SchemeUnimperative is quite similar to Scheme. In Scheme we can write a factorial function as:
(define factorial
(lambda (n)
(if (zero? n)
1
(* n (fact (- n 1))))))
In Unimperative we can write the equivalent function as:
Function factorial =
(IfZero, _1,
1,
(Mult, _1, (Self, (Dec, _1))));
Basic UsageIn many language we call functions by writing: MyFxn(x, y) In the Unimperative programming language we instead write: (MyFxn, x, y) The first element following an open paranthesis, and followed by a comma, is always treated as a function which will be evaluated. The elements which follow are passed as arguments to the function. Other functions after the first one in a list are not evaluate: (MyFxn, OtherFxn) This evaluates the function MyFxn and passes the OtherFxn as a parameter without evaluating it. A function must be followed by at least one argument in order to be evaluated. The evaluation operator is the combination of paranthesis and comma: (xxx, The following code does not evaluate MyFxn: (MyFxn) If we wanted to evaluate MyFxn we would have to write: (MyFxn, nil) Alternatively we could also write: (Eval, MyFxn) Defining FunctionsTo define a function in Unimperative we do so as follows: Function MyFxn = (Add, _1, _2); The _1 and _2 are place holders which refer to the first and second argument respectively. An Interesting TwistThe Unimperative programming language has a surpise: it is completely legal C++, and doesn't use any macros! An Unimperative library will be available soon as part of the next OOTL ( Object Oriented Template Library ) release from http://www.ootl.org By cdiggins at 2005-01-31 19:39 | LtU Forum | previous forum topic | next forum topic | other blogs | 9219 reads
|
Browse archives
Active forum topics |
Recent comments
4 days 10 min ago
4 days 26 min ago
4 days 27 min ago
3 weeks 4 days ago
4 weeks 3 days ago
4 weeks 3 days ago
4 weeks 4 days ago
4 weeks 4 days ago
4 weeks 4 days ago
5 weeks 9 hours ago