Wafl Home

Program Structure Tutorial

Arrow Syntax

Because 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 arrow 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 arrow syntax:

x1->f(x2,...,xn)

These two syntaxes have the same semantics.

The usage of arrow syntax usually results in more readable source code. For example, consider definitions of two mutually equivalent functions in the following example.

(Having arrow syntax in mind, any function that has one 'main' argument, eg. evaluates a kind of transformation of an argument, should be defined in such way that the 'main' 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" #}

 

Table of Contents

Let's Start

Program Structure

Primitive Data Types

List

Tuple

Record

HTML

Command Line Interpreter

Using Web Servers

Syntax

Examples

Tips

The most of examples evaluates with both command line and Web server Wafl interpreters. If any example is based on specific features of an interpreter, it is explicitly annotated.