FPr
- Appeared in:
- 2009
- Influenced by:
- Paradigm:
- Typing discipline:
- File extensions:
- .fp
- Versions and implementations (Collapse all | Expand all):
FPr (Function-level Programming right-associative) is an implementation of an FP-System. FPr features the list-technics of Lisp and some technics of object-oriented programming especially the use of the infix notation. FPr offers an alternative for the usage of local variables.
Elements of syntax:
| Non-nestable comments | "<comment>" |
|---|---|
| Case-sensitivity | no |
| Function identifier regexp | abc or +-*/ |
| Function definition | ident == term |
| Sequence | ( ... ) |
| If - then - else | test -> then ; else |
| While condition do | test ->* body |
| For each value in a numeric range, 1 increment | list map term& |
Examples:
Factorial:
Example for versions FPrThis example provides a list of factorials from 0 up to 16. Factorialb is the non-recursive version.
(seq:16) map factorial&
seq == (0&),iota
factorial == (id=0&) -> (1&) ; id*(factorial°id-1&)
factorialb == ((1&),iota) \ (1*2)&
Quadratic equation:
Example for versions FPrThis example defines the function quadratic which accepts coefficients of quadratic equation and outputs the roots as string. Usage is quadratic:(list::1 _2 1)
"quadratic : (list :: <a> <b> <c>)"
quadratic==( ((a#)=0&)->(string::'Not a quadratic equation.');
( ((d#)=0&)->((string::'x = ')++str°p1#);
((d#)>0&)->((string::'x1 = ')++(str°(p1#)+p2#)
++(string::'; x2 = ')++str°(p1#)-p2#);
(string::'x1 = (')++(str°p1#)++(string::', ')++(str°p2#)
++(string::'); x2 = (')++(str°p1#)++(string::', ')++(str°neg°p2#)++(string::')')
) ° (p1#=neg°(b#)/((2&)*a#))
° (p2#=(sqrt°abs°d#)/((2&)*a#))
° d#=((b#)*b#)-(4&)*(a#)*c#
)<-a b c
sqrt==id^0.5&
abs==(id<0&)->neg;id
Comments
]]>blog comments powered by Disqus
]]>