|
![]() |
||||||||||||||
Program Structure TutorialDot SyntaxBecause of functional semantics of subprograms, the source code of programs written in functional programming languages is very often quite unreadable. One of most important programming languages in the history of computing, LISP (originally from "LISt Processing"), is often called "Lots of Irritating Small Parenthesis", because of theirs usage in function application syntax. The problem is approached in Wafl by object-oriented-like dot syntax. In short, any function defined for at least one argument is applicable not only using usual syntax f(x1,x2,...,xn) but also, using the dot syntax: x1.f(x2,...,xn) These two syntaxes have the same semantics. The usage of dot syntax usually results in more readable source code. For example, consider definitions of two mutually equivalent functions in the following example. (Having dot syntax in mind, any function that evaluates a kind of transformation of an argument, should be defined in such way that transformed argument is the first one.) Source code:{# f('abcdABCDabcdABCD'), g('abcdABCDabcdABCD') #} where{ f(s) = s.subStr(5,8) .strReplaceAll('a','B') .strReplaceAll('b','A') .strLowerCase(); g(s) = strLowerCase( strReplaceAll( strReplaceAll( subStr(s,5,8), 'a','B' ), 'b','A' ) ); } Result:{# "bcdbacda", "bcdbacda" #}
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||