Table of Contents

1 Introduction

1.1 Command Line Interpreter

1.2 Hello World

1.3 Main Wafl Concepts

1.4 Introduction to the Types

2 Program Structure

2.1 Program Is an Expression

2.2 Comments

2.3 Tuples

2.4 Local Definitions

2.5 Function Definition

2.6 Named Expression Definition

2.7 No Variables

2.8 The Order of the Definitions

2.9 Conditional Expression if

2.10 Conditional Expression switch

2.11 Recursion

2.12 Libraries

3 Programming With Functions

3.1 Strict Type Checking

3.2 Automatic Type Inference

3.3 Polymorphism

3.4 Higher Order Functions

3.5 Partial Application

3.6 Lambda Functions

3.7 Lambda Closures

3.8 Operators as Functions

3.9 Dot Operator

3.10 Explicit Computation State

3.11 Cached Functions

4 Primitive Types

4.1 Literals

4.2 Operators

4.3 Conversion Functions

4.4 Integer Functions

4.5 Float Functions

4.6 String Functions

5 List Type

5.1 List Literals

5.2 Basic List Functions

5.3 Basic List Processing

5.4 Advanced List Processing

5.5 More List Functions

5.6 Functions map and zip

5.7 Functions foldr, foldl and fold

5.8 Functions filter, find and filterMap

5.9 Functions forall and exists

5.10 Functions count and countRep

5.11 Functions sort and sortBy

5.12 Functions in and contains

5.13 Lazy Lists

6 Structured Types

6.1 Array Type

6.2 Map Type

6.3 Tuple Type

6.4 Record Type

7 Elements of Wafl Library

7.1 Program Control

7.2 File Reading

7.3 File Writing

7.4 File Operations

7.5 Directory Operations

7.6 Regex Functions

7.7 Command Line

7.8 Web and HTTP Functions

7.9 Wafl to JSON

7.10 Wafl Program Evaluation

8 Parallelization

8.1 Wafl and Parallelization

8.2 Parallel Functions

9 Core Library Reference

9.1 Main Library

9.2 Command Line Library

9.3 Web Library

9.4 XML Library

9.5 Drawing Library (SDL)

9.6 Timer Library

9.7 Edlib Library

10 Command Line Reference

10.1 Command Line Options

10.2 Configuration Files

10.3 ANSI Control Codes

11 Advanced

11.1 JIT

11.2 Wafl Binary Libraries

12 More Content…

12.1 Soon…

 

 

Last update: 29.01.2025.

Wafl

Wafl

Tutorial / 9 - Core Library Reference

Open printable version

9 Core Library Reference

A large part of the Wafl core library has already been presented in the previous chapters. Here we present a complete reference of the core library in a compact form. The functions and operators are listed in alphabetical order and organized by main sections. For each function, its type and a short description are specified.

The Wafl interpreter can list all supported functions and operators. To get a compact list, execute:

clwafl -listlib

For a more detailed list, execute:

clwafl -listlib -verbose

To find all functions that have the given substring (in the following example - str) in their name, run:

clwafl -listlib:str

or:

clwafl -listlib:str -verbose

Further details can be found in the Command Line Reference.

9.1 Main Library

Function / Type and Description

! A

(Bool -> Bool)
Negates the given logical value.

% A

(Sequence['1]['2] -> Sequence['1]['2])
Get a sequence tail.

* A

(Sequence['1]['2] -> '2)
Get a sequence head. Not defined for empty sequence.

- A

(Numeric['1] -> Numeric['1])
Unary negation operator.

A != B

('1 * '1 -> Bool)
Not-equal-to operator.

A $

('1 -> String)
Converts a value to a string.

A % B

(Int * Int -> Int)
Integer remainder operator.

A %% B

(Int * Int -> Int)
Integer modulus operator. Always positive.

A & B

(Int * Int -> Int)
Bitwise AND operator.

A && B

(Bool * Bool -> Bool)
Boolean conjunction operator.

A * B

(Numeric['1] * Numeric['1] -> Numeric['1])
Binary subtraction operator.

A ** B

(Numeric['1] * Numeric['1] -> Numeric['1])
Power operator: A ** B = A to the power of B

A + B

(Value['1] * Value['1] -> Value['1])
Binary addition operator.

A ++ B

(SequenceStr['1]['2] * SequenceStr['1]['2] -> SequenceStr['1]['2])
Appends the the second sequence to the first sequence.

A - B

(Numeric['1] * Numeric['1] -> Numeric['1])
Binary subtraction operator.

A .. B

(Int * Int -> List[Int])
Returns the list of integers in the range:
    2..5 = [2,3,4,5]

A / B

(Numeric['1] * Numeric['1] -> Numeric['1])
Binary division operator.

A : B

('1 * List['1] -> List['1])
Operator that constructs a new list from the given head and tail.

A < B

(Value['1] * Value['1] -> Bool)
Less-than operator.

A << B

(Int * Int -> Int)
Bitwise left shift operator.

A <= B

(Value['1] * Value['1] -> Bool)
Less-than-or-equal-to operator.

A == B

('1 * '1 -> Bool)
Equal-to operator.

A > B

(Value['1] * Value['1] -> Bool)
Greater-than operator.

A >= B

(Value['1] * Value['1] -> Bool)
Greater-than-or-equal-to operator.

A >> B

(Int * Int -> Int)
Integer right shift operator.

A | B

(Int * Int -> Int)
Bitwise OR operator.

A || B

(Bool * Bool -> Bool)
Boolean disjunction operator.

A[ : B ]

(SequenceStr['2]['1] * Int -> SequenceStr['2]['1])
Extracts a prefix of the sequence with N elements:
    seq[:N]

A[ B : C ]

(SequenceStr['2]['1] * Int * Int -> SequenceStr['2]['1])
Extracts a sequence segment from Nth to (M-1)th element:
    seq[N:M]

A[ B : ]

(SequenceStr['2]['1] * Int -> SequenceStr['2]['1])
Extracts a suffix of the sequence with N elements:
    seq[N:]

A[ B ]

(Indexable['1]['2]['3] * '2 -> '3)
Extracts an element from the indexable collection:
    col[idx]

EncodeUrlQuery

(Map[String][String] -> String)
Encodes variable set for HTTP query string.

JoinValueSets

(Map[String][String] * Map[String][String] -> Map[String][String])
Joins two variable sets.

RemoveFromValueSet

(Map[String][String] * String -> Map[String][String])
Removes a variable with the given name from the variable set.

UpdateValueSet

(Map[String][String] * String * String -> Map[String][String])
Updates the variable set with given var. name and var. value.

abs

(Numeric['1] -> Numeric['1])
Absolute value.

acos

(Float -> Float)
Inverse cosine function.

append

(SequenceStr['1]['2] * SequenceStr['1]['2] -> SequenceStr['1]['2])
Appends the second sequence to the first sequence.

appendAll

(Sequence['1][SequenceStr['2]['3]] -> SequenceStr['2]['3])
Appends all sequences in the given sequence.

asArray

(Sequence['1]['2] -> Array['2])
Converts a sequence to an array

asBool

(Value['1] -> Bool)
Converts a value to a bool.

asChar

(PrimeNotString['1] -> String)
Converts a value to a character.

asFloat

(PrimeNotFloat['1] -> Float)
Converts a value to a float.

asInt

(PrimeNotInt['1] -> Int)
Converts a value to an integer.

asList

(Sequence['1]['2] -> List['2])
Converts a sequence to a list

asPreview

('1 -> String)
Converts a value to a shortened string.

asString

('1 -> String)
Converts a value to a string.

ascii

(String -> Int)
Returns ascii code of the first character of the string.

aside

('1 * ('1 -> '2) -> '1)
Applies 2nd arg. to 1st, discards the result and returns 1st arg:
    aside(x,fn) == fn(x).return(x)

asin

(Float -> Float)
Inverse sine function.

atan

(Float -> Float)
Inverse tangent function.

atan2

(Float * Float -> Float)
Inverse tangent function:
    atan2(y,x) = atan(y/x)

between

(Numeric['1] * Numeric['1] * Numeric['1] -> Bool)
Checks whether the 1st arg. lies between 2nd and 3rd arguments.
    x.between(a,b) == x >= a and x <= b

ceil

(Float -> Int)
Rounds a float to a closest not smaller integer.

contains

(Sequence['2]['1] * '1 -> Bool)
Checks whether the element is contained in the sequence:
    seq.contains(el)

cos

(Float -> Float)
Cosine function.

count

(Sequence['2]['1] * ('1 -> Bool) -> Int)
Counts the sequence elements that fulfill the condition:
    count(seq,cond)

countRep

(Sequence['2]['1] -> Map['1][Int])
Creates a catalog from the sequence. Keys are the distinct elements, and values are the number of occurrences.

createMap

(Array[Value['1]] * Array['2] -> Map[Value['1]]['2])
Creates a catalog from given arrays.

debugIsOn

( -> Bool)
Checks whether the debug mode is turned ‘on’.

debugOff

('1 -> '1)
Turns debug mode ‘off’ and returns the argument.

debugOn

('1 -> '1)
Turns debug mode ‘on’ and returns the argument.

debugState

( -> String)
Evaluates the debug state string.

dirCreate

(String -> Bool)
Creates a directory.

dirDelete

(String -> Bool)
Deletes a directory, if it is empty

dirExists

(String -> Bool)
Checks whether a directory with the given name exists.

dirFiles

(String -> List[String])
Returns the list of files that fulfill the given filter.

dirSubdirs

(String -> List[String])
Returns the list of subdirs that fulfill the given filter.

dynSqlCommand

(String -> Bool)
Executes SQL command given in a string dynamically.

dynSqlQuery

(String -> Record[errCode:Int, errText:String, ok:Bool, result:List[Map[String][String]]])
Executes SQL query given in a string dynamically.

empty

(Indexable['1]['2]['3] -> Bool)
Checks whether the collection is empty.

exists

(Sequence['2]['1] * ('1 -> Bool) -> Bool)
Checks whether any sequence element fulfills the condition:
    exists(sequence,cond)

exp

(Float -> Float)
Exponential function.

fileDelete

(String -> Bool)
Deletes a file.

fileErrors

( -> Bool)
Checks if some errors were detected since last reset.

fileErrorsMsgs

( -> List[String])
Returns the list of all detected file op. error messages.

fileErrorsReset

( -> Bool)
Clears all detected error messages.

fileExists

(String -> Bool)
Checks whether a file with the given name exists.

fileLastError

( -> Bool)
Checks if last file op. produced errors.

fileLastErrorMsg

( -> String)
Returns last file op. error message, or empty string otherwise.

fileNewTempName

( -> String)
Generates a new temporary file name.

fileOrDirExists

(String -> Bool)
Checks whether a file or a directory with the given name exists.

fileRead

(String -> String)
Reads entire file to a string.

fileReadPart

(String * Int * Int -> String)
Reads a part of the file, from given 0-based position and with given length in bytes:
    fileReadPart( fname, pos, bytelen )

fileSize

(String -> Int)
Returns the file size.

fileTruncate

(String -> Bool)
Truncates a file. Returns false if truncate fails or file does not exist.

fileWrite

(String * String -> String)
Writes string to a file and truncates old content:
    fileWrite( fname, content )

fileWriteAppend

(String * String -> String)
Writes string to a file by appending to the file end.
    fileWriteAppend( fname, content )

fileWriteAppendTo

(String * String -> String)
Writes string to a file by appending to the file end.
    fileWriteAppendTo( content, fname )

fileWriteTo

(String * String -> String)
Writes string to a file and truncates old content:
    fileWriteTo( content, fname )

filter

(Sequence['2]['1] * ('1 -> Bool) -> Sequence['2]['1])
Extracts the sequence elements which satisfy the given condition

filterMap

(Sequence['3]['1] * ('1 -> Bool) * ('1 -> '2) -> Sequence['3]['2])
Maps a function to sequence elements which satisfy the condition.
    mapFilter(seq,cond,fn) == map(filter(seq,cond),fn)

filterN

(Sequence['2]['1] * ('1 -> Bool) * Int -> Sequence['2]['1])
Extracts at most N elements which satisfy the given condition.

filter_par

(Sequence['2]['1] * ('1 -> Bool) -> Sequence['2]['1])
Extracts the sequence elements that fulfill the given condition.

filter_seq

(Sequence['2]['1] * ('1 -> Bool) -> Sequence['2]['1])
Extracts the sequence elements which satisfy the given condition.

find

(Sequence['2]['1] * ('1 -> Bool) -> Sequence['2][Int])
Finds the indexes of the elements which satisfy the given condition.

findKey

(Map['2]['1] * '2 -> Int)
Finds a position of the given key, or -1 if not found.

findN

(Sequence['2]['1] * ('1 -> Bool) * Int -> Sequence['2][Int])
Finds at most N indexes of the elements which satisfy the given condition.

findValue

(Map['2]['1] * '1 -> Int)
Finds a position of the given value, or -1 if not found.

floor

(Float -> Int)
Rounds a float to a closest not greater integer.

fold

(Sequence['2]['1] * ('1 * '1 -> '1) * '1 -> '1)
Returns the sequence fold by an associative function:
    fold == foldl == foldr

fold_par

(Sequence['2]['1] * ('1 * '1 -> '1) * '1 -> '1)
Folds the sequence elements in parallel. [‘fn’ must be associative]: [‘zero’ must be ZERO, because it can be used many times]:
    fold_par(seq,fn,zero) == foldl(seq,fn,zero) == foldr(seq,fn,zero)

fold_seq

(Sequence['2]['1] * ('1 * '1 -> '1) * '1 -> '1)
Non-parallel fold of sequence by an associative function:
    fold_seq == foldl == foldr

foldl

(Sequence['3]['2] * ('1 * '2 -> '1) * '1 -> '1)
Returns the left associative fold of sequence elements:
    foldl([a,b,c],fn,zero) = fn(fn(fn(zero,a),b),c)

foldr

(Sequence['3]['2] * ('2 * '1 -> '1) * '1 -> '1)
Returns the right associative fold of sequence elements:
    foldr([a,b,c],fn,zero) = fn(a,fn(b,fn(c,zero)))

forall

(Sequence['2]['1] * ('1 -> Bool) -> Bool)
Checks whether the given condition applies to all sequence elements:
    forall(list,cond).

forced

(List['1] -> List['1])
Returns the list, but forces any delayed evaluation.

groupBy

(Sequence['3]['1] * ('1 -> '2) -> Map['2][List['1]])
Creates a catalog from the sequence. Each catalog element is a list of all elements mapped to the key value by the given function.

hasKey

(Map['2]['1] * '2 -> Bool)
Checks whether there is a given key in the map.

hasValue

(Map['2]['1] * '1 -> Bool)
Checks whether there is a given value in the map.

hd

(List['1] -> '1)
Extracts the list head. Not defined for empty list.

ifNull

(String * String -> String)
Replaces null with the given value:
    ifNull(x,c) = if isNull(x) then c else x

in

('1 * Sequence['2]['1] -> Bool)
Checks whether the element is in the sequence:
    el.in(seq)

intRange

(Int * Int -> List[Int])
Returns the list of integers in the range:
    intRange(2,5) = [2,3,4]

intRangeBy

(Int * Int * Int -> List[Int])
Returns the list of integers in the given range with a given step:
    intRangeBy(2,10,2) = [2,4,6,8]

intRangeWithLast

(Int * Int -> List[Int])
Returns the list of integers in the range:
    intRangeWithLast(2,5) = [2,3,4,5]

isNull

(String -> Bool)
Checks whether a string is a database NULL value.

iterate

('1 * Int * Int * ('1 * Int -> '1) -> '1)
Left associative folding of specified integers range:
    iterate(zero,2,4,fn) = fn(fn(fn(zero,2),3),4)
        = zero.fn(2).fn(3).fn(4)
        = (2..4).foldl(fn,zero)

iterateBy

('1 * Int * Int * Int * ('1 * Int -> '1) -> '1)
Left associative folding of specified integers range by step:
    iterateBy(zero,2,6,2,fn) = fn(fn(fn(zero,2),4),6)
        = zero.fn(2).fn(4).fn(6)
        = [2,4,6].foldl(fn,zero)

key

(Map['2]['1] * Int -> '2)
Returns Nth key (from 0).

keys

(Map['2]['1] -> Array['2])
Returns map keys.

leftAggregate

(Sequence['3]['2] * ('1 * '2 -> '1) * '1 -> '1)
Returns the left associative fold of sequence elements (foldl).

length

(Indexable['1]['2]['3] -> Int)
Returns the size of the collection.

ln

(Float -> Float)
Natural logarithm.

log

(Float -> Float)
Logarithm to the base 10.

log2

(Float -> Float)
Logarithm to the base 2.

longerThan

(SequenceStr['1]['2] * Int -> Bool)
Checks whether the sequence is longer than the given integer.

map

(Sequence['2]['1] * ('1 -> '3) -> Sequence['2]['3])
Maps the function to sequence elements:
    map(seq,fun)

mapIdx

(Sequence['1]['2] * (Int * '2 -> '3) -> Sequence['1]['3])
Maps the function to sequence elements:
    mapIdx(seq,fun)

mapIdx_par

(Sequence['1]['2] * (Int * '2 -> '3) -> Sequence['1]['3])
Maps the fun. to sequence elements (in parallel):
    mapIdx_par(seq,fun)

mapIdx_seq

(Sequence['1]['2] * (Int * '2 -> '3) -> Sequence['1]['3])
Maps the function to sequence elements (non-parallel):
    mapIdx_seq(seq,fun)

map_par

(Sequence['2]['1] * ('1 -> '3) -> Sequence['2]['3])
Maps the function to sequence elements (in parallel):
    map_par(seq,fun)

map_seq

(Sequence['2]['1] * ('1 -> '3) -> Sequence['2]['3])
Maps the function to sequence elements (non-parallel):
    map_seq(seq,fun)

map_seq_opt

(Array[Int] * (Int -> Int) -> Array[Int])
DO NOT USE Maps the function to array elements (non-parallel):
    map_seq(arr,fun)

newArray

(Int * '1 -> Array['1])
Generates an array with given number of elements of given value:
    newArray(5,'a') == [# 'a', 'a', 'a', 'a', 'a' #]

newArrayFn

(Int * (Int -> '1) -> Array['1])
Generates an array with given number of elements and computes each of the elements using given function on its index:
    newArrayFn(5,\x:x*x) == [# 0, 1, 4, 9, 16 #]

newArrayFn_par

(Int * (Int -> '1) -> Array['1])
Creates an array with given number of elements and computes each of the elements using given function on its index (in parallel):
    newArrayFn_par(5,\x:x*x) == [# 0, 1, 4, 9, 16 #]

newArrayFn_seq

(Int * (Int -> '1) -> Array['1])
Generates an array with given number of elements and computes each of the elements using given function on its index (non-parallel):
    newArrayFn_seq(5,\x:x*x) == [# 0, 1, 4, 9, 16 #]

newArrayFn_seq_opt

(Int * (Int -> '1) -> Array['1])
DO NOT USE!!! Generates an array with given number of elements and computes each of the elements using given function on its index (non-parallel):
    newArrayFn_seq_opt(5,\x:x*x) == [# 0, 1, 4, 9, 16 #]

parallel

('1 -> '1)
Marks an expression to be parallelized, if possible.

pow

(Float * Float -> Float)
Power function:
    pow(A,B) = A ** B = A to the power of B

random

(Int -> Int)
Returns a random value in range [0,A-1], or 0 for A<2.

regexMatch

(String * String -> Bool)
Checks whether a string matches given regular expression.

regexMatchI

(String * String -> Bool)
Checks whether a string matches given regular expression. Ignores upper and lower case.

regexPos

(String * String -> Int)
Finds the first regex matching position in the given string.

regexPosAll

(String * String -> List[Int])
Finds all regex matching positions in the given string.

regexPosAllI

(String * String -> List[Int])
Finds all regex matching positions in the given string. Ignores upper and lower case.

regexPosI

(String * String -> Int)
Finds the first regex matching position in the given string. Ignores upper and lower case.

regexReplace

(String * String * String -> String)
Replaces all matching of a regex with the given string.

regexReplaceI

(String * String * String -> String)
Replaces all matching of a regex with the given string. Ignores upper and lower case.

regexSearch

(String * String -> List[String])
Searches for the regex matching in the given string.

regexSearchAll

(String * String -> List[List[String]])
Searches for all regex matchings in the given string.

regexSearchAllI

(String * String -> List[List[String]])
Searches for all regex matchings in the given string. Ignores upper and lower case.

regexSearchI

(String * String -> List[String])
Searches for the regex matching in the given string. Ignores upper and lower case.

repeatUntil

('1 * ('1 -> '1) * ('1 -> Bool) -> '1)
Repeats the function evaluation until the condition is met:
    repeatUntil(x,fn,cond) =
        if cond(x) then x
        else fn(x).repeatUntil(fn,cond)

return

('1 * '2 -> '2)
Evaluates both arguments, discards the 1st result and returns 2nd one.

rightAggregate

(Sequence['3]['2] * ('2 * '1 -> '1) * '1 -> '1)
Returns the right associative fold of sequence elements (foldr).

round

(Float -> Int)
Rounds a float to a closest integer.

roundTo

(Float * Float -> Float)
Rounds a float value; 2nd arg. defines a lowest significant digit.
    roundTo( 123.456789, 0.01 ) = 123.46

sequential

('1 -> '1)
Force the expression to run sequentially.

sgn

(Numeric['1] -> Numeric['1])
Returns sign(x) = x/abs(x) or zero if x is zero.

sin

(Float -> Float)
Sine function.

size

(Indexable['1]['2]['3] -> Int)
Returns the size of the collection.

sort

(Sequence['2][Value['1]] -> Sequence['2][Value['1]])
Sorts value sequence.

sortAscii

(Sequence['2][Value['1]] -> Sequence['2][Value['1]])
Sorts string sequence by Ascii table.

sortBy

(Sequence['2]['1] * ('1 * '1 -> Bool) -> Sequence['2]['1])
Sorts the sequence using given comparator.

sortUtf8

(Sequence['2][Value['1]] -> Sequence['2][Value['1]])
Sorts string sequence by UTF-8 table.

sqrt

(Float -> Float)
Square root.

strBeg

(String * String -> Bool)
Checks whether the 2nd string is at the beginning of the 1st.

strCat

(String * String -> String)
String concatenation. The same as string addition.

strChars

(String -> List[String])
Splits a string to a list of characters.

strCountSub

(String * String -> Int)
Count occurrences of substring in the given string:
    strCountSub('aaaaaA','aa') == 4

strCountSubDis

(String * String -> Int)
Count disjunct occurrences of substring in the given string:
    strCountSub('aaaaaA','aa') == 2

strCountSubDisI

(String * String -> Int)
Same as strCountSubDis, but ignores upper and lower case:
    strCountSub('aaaaaA','aa') == 3

strCountSubI

(String * String -> Int)
Same as strCountSub, but ignores upper and lower case:
    strCountSub('aaaaaA','aa') == 5

strEncodeHtml

(String -> String)
Encodes the string for HTML.

strEncodeSql

(String -> String)
Encodes the string for SQL.

strEncodeUri

(String -> String)
Encodes the string for URI.

strEncodeWafl

(String -> String)
Encodes the string for Wafl code.

strEnd

(String * String -> Bool)
Checks whether the 2nd string is at the end of the 1st.

strJoin

(Sequence['1][String] * String -> String)
Joins (concatenates) a sequence of strings, adding the given separator.

strLTrim

(String -> String)
Trims all spaces from left side.

strLastPos

(String * String -> Int)
Finds last position of a substring in the string, or -1 if not found.

strLastPosI

(String * String -> Int)
Same as strLastPos, but ignores upper and lower case.

strLeft

(String * Int -> String)
Returns first N characters of the string. If N is negative, returns all but last -N elements.

strLen

(String -> Int)
Returns the length of the character string.

strLocale

( -> String)
Returns the current locale name.

strLowerCase

(String -> String)
Converts all letters to lower case.

strNextLastPos

(String * String * Int -> Int)
Finds next last position of a substring in the string, before given pos.

strNextLastPosI

(String * String * Int -> Int)
Same as strNextLastPosI, but ignores upper and lower case.

strNextPos

(String * String * Int -> Int)
Finds next position of a substring in the string, after given pos.

strNextPosI

(String * String * Int -> Int)
Same as strNextPos, but ignores upper and lower case.

strPos

(String * String -> Int)
Finds first position of a substring in the string, or -1 if not found.

strPosI

(String * String -> Int)
Same as strPos, but ignores upper and lower case.

strRTrim

(String -> String)
Trims all spaces from right side.

strReplace

(String * String * String * Int -> String)
Replaces Nth occurrence of substring with given string:
    strReplace('ababa','b','c',2) == 'abaca'

strReplaceAll

(String * String * String -> String)
Replaces all occurrences of substring with given string.

strReplaceAllI

(String * String * String -> String)
Same as strReplaceAll, but ignores upper and lower case.

strReplaceI

(String * String * String * Int -> String)
Same as strReplace, but ignores upper and lower case.

strReverse

(String -> String)
Reverses the string.

strRight

(String * Int -> String)
Returns last N characters of the string. If N is negative, returns all but first -N elements.

strSplit

(String * String -> List[String])
Splits a string to a list of string, by extracting the given separator.

strSplitLines

(String -> List[String])
Splits a string to a list of string, by extracting new-line separator.

strSplitLinesTrim

(String -> List[String])
Splits a string to a list of string, by extracting new-line separator. All spaces are trimmed from each segment from left and right side.

strSplitTrim

(String * String -> List[String])
Splits a string to a list of string, by extracting the given separator. All spaces are trimmed from each segment from left and right side.

strTrim

(String -> String)
Trims all spaces from both sides.

strUpperCase

(String -> String)
Converts all letters to upper case.

sub

(SequenceStr['2]['1] * Int * Int -> SequenceStr['2]['1])
Extracts the subsequence from given 0-based position and given length:
    sub(seq,pos,len)

subList

(List['1] * Int * Int -> List['1])
Extracts the sub-list from given 0-based position and given length:
    subList(list,pos,len)
[Deprecated. Use ‘sub’.]

subStr

(String * Int * Int -> String)
Returns a substring from given position (from 0) and with given length. [Deprecated. Use ‘sub’.]

sysEnvDetails

( -> Record[dirSep:String, maxInt:Int, minInt:Int, module:String, nlSep:String])
Returns system environment description.

sysLargestFreeMemoryBlock

( -> Int)
Returns largest free memory block.

sysLastError

( -> String)
Returns the last system error description, or empty string if no errors occurred.

sysLibContent

( -> String)
Prints the Wafl library content in a string.

tan

(Float -> Float)
Tangent function.

tl

(List['1] -> List['1])
Extracts the list tail.

toFmtJSON

('1 -> String)
Converts a value to a string in pretty JSON format.

toJSON

('1 -> String)
Converts a value to a string in JSON format.

toString

(Float * Int -> String)
Converts a float value to a string with given precision.

utfAddBom

(String -> String)
Adds a UTF-8 BOM, if not already present.

utfAt

(String * Int -> String)
Returns a code point at given position, indexed by codepoints.

utfBom

( -> String)
Returns UTF-8 BOM sequence.

utfChars

(String -> List[String])
Splits a string to a list of UTF-8 code points.

utfHasBom

(String -> Bool)
Checks whether a string begins with UTF-8 BOM.

utfIsBom

(String -> Bool)
Checks whether a string content is UTF-8 BOM.

utfIsValid

(String -> Bool)
Checks whether a string is a valid UTF-8 encoded string.

utfLeft

(String * Int -> String)
Returns first N UTF-8 code points of the string.

utfLen

(String -> Int)
Returns UTF-8 length, as a number of complete code points.

utfRepInvalid

(String * String -> String)
Replaces invalide code points with the given character.

utfReverse

(String -> String)
Reverses UTF-8 string.

utfRight

(String * Int -> String)
Returns last N UTF-8 code points of the string.

utfSlice

(String * Int * Int -> String)
Returns a substring between two given positions, indexing complete UTF-8 code points instead of characters.

utfSub

(String * Int * Int -> String)
Returns a substring from given position (from 0) and with given length, indexing complete UTF-8 code points instead of characters.

utfTrimBom

(String -> String)
Trims leading BOM, if present.

value

(Map['2]['1] * Int -> '1)
Returns Nth value.

values

(Map['2]['1] -> Array['1])
Returns map values.

zip

(Sequence['4]['1] * Sequence['4]['2] -> Sequence['4][Tuple['1, '2]])
Zips two sequences to a sequence of pairs.

zipBy

(Sequence['4]['1] * Sequence['4]['2] * ('1 * '2 -> '3) -> Sequence['4]['3])
Zips two sequences by given function:
    zipBy(seq1, seq2 ,fun)

zipByIdx

(Sequence['4]['1] * Sequence['4]['2] * (Int * '1 * '2 -> '3) -> Sequence['4]['3])
Zips two sequences and indexes by given function:
    zipByIdx(seq1, seq2 ,fun)

zipWith

(Sequence['4]['1] * Sequence['4]['2] * ('1 * '2 -> '3) -> Sequence['4]['3])
Zips two sequences by given function:
    zipWith(seq1, seq2 ,fun)
[Deprecated. Use ‘zipBy’.]

~ A

(Int -> Int)
Bitwise NOT operator.

9.2 Command Line Library

Function / Type and Description

$ A

(Int -> String)
Return a command line argument:
    $1 = cmdLineArgs()[1]

cmdEcho

('1 * String -> '1)
Echo 2nd argument to the console and return the 1st argument. [Deprecated. Use ‘echoTxt’.]

cmdExecute

(String -> String)
Execute the command in the active console and return the result.

cmdLastError

( -> Int)
Get integer code of last command status.

cmdLineArgs

( -> List[String])
Return a list of command line arguments.

cmdLineArgsCount

( -> Int)
Return a number of command line arguments.

cmdPrint

(String -> String)
Write a string to the console and return the same string. [Deprecated. Use ‘echo’.]

cmdSetExitCode

('1 * Int -> '1)
Set program exit code to second argument and return the first one.

cmdShellExecute

(String -> String)
Open new shell, execute the command in it and return the result.

cmdWafl

(String * List[String] -> String)
Run Wafl program file in a command line shell with given arguments and return the result. All arguments are passed to Wafl program. No arguments apply to interpreter. The output is redirected to the caller’s output stream.

cmdWaflSrc

(String * List[String] -> String)
Run Wafl program source in a command line shell with given arguments and return the result. All arguments are passed to Wafl program. No arguments apply to interpreter. The output is redirected to the caller’s output stream.

cmdWaflX

(String * RecordX[]['1] -> String)
Run Wafl program file in a command line shell with given options and return the result. Options are specified as a record fields:
    cmdLineArgs - the list of command line arguments to pass
        to the program (List[String]);
        coutFile - the full filename of the output redirection file;
        if '*null*' is specified, output is discarded;
        if empty string is specified (default),
        the caller's output stream is used .

echo

('1 -> '1)
Write the argument’s string representation to the console and return the argument:
    echo(x) == echoTxt( x, x.asString() )

echoFn

('1 * ('1 -> String) -> '1)
Apply the function to the 1st arg. and write the result to the console:
    echoFn( x, fn ) == echoTxt( x, fn(x) )

echoLn

('1 -> '1)
Write the argument’s string representation and new line to the console and return the argument:
    echoLn(x) == echoTxt( x, x.asString() + '\n' )

echoTxt

('1 * String -> '1)
Write the second argument to the console and return the first argument.

input

(String -> String)
Write a string to the console, wait for input and return it.

9.3 Web Library

Function / Type and Description

Form

( -> Map[String][String])
Get form variable set.

FormValue

(String -> String)
Get value of a given form variable.

Service

( -> Map[String][String])
Get service variable set.

ServiceValue

(String -> String)
Get value of a given service variable.

Session

( -> Map[String][String])
Get session variable set.

SessionValue

(String -> String)
Get value of a given session variable.

answerAction

( -> String)
Automatic action URI generator for forms in questions.

ask

(String -> Map[String][String])
Ask a question by sending the given page content to the client. Returns the next client’s request.

httpGet

(String -> String)
Get WWW content using HTTP/HTTPS GET method.[Deprecated. Use ‘Curl’ library.]

httpGetSize

(String -> Int)
Get WWW content length using HTTP/HTTPS HEADER method.[Deprecated. Use ‘Curl’ library.]

httpGet_callback

(String * (Int * Int -> Int) -> String)
Get WWW content using HTTP/HTTPS GET method, with progress callback[Deprecated. Use ‘Curl’ library.]

httpHost

( -> String)
Get HTTP host for current request.

httpPathInfo

( -> String)
Get HTTP path info for current request.

httpScript

( -> String)
Get HTTP script for current request.

mimeAsAttachment

(MimeResource * String -> MimeResource)
Adds the MIME resource object filename and flags it as an attachment.

mimeContent

(MimeResource -> String)
Returns the MIME content.

mimeFilename

(MimeResource -> String)
Returns the MIME filename.

mimeResource

(String * String -> MimeResource)
Creates a MIME resource object.

mimeSetFilename

(MimeResource * String -> MimeResource)
Adds the MIME resource object filename.

mimeType

(MimeResource -> String)
Returns the MIME resource type.

9.4 XML Library

This library is currently under development.

Function / Type and Description

xmlParse

(String -> XmlTag)
Parses XML tag from string.

xmlParseI

(String -> XmlTag)
Parses XML tag from string, ignoring upper and lower case.

xmlSubTags

(XmlTag -> List[XmlTag])
Returns all subtags of a XML tag.

xmlSubTagsFilter

(XmlTag * String -> List[XmlTag])
Returns all subtags of a XML tag with appropriate filter.

xmlTagAttr

(XmlTag * String -> String)
Returns value of a XML tag attribute.

xmlTagAttrs

(XmlTag -> List[Record[name:String, value:String]])
Returns all XML tag attributes.

xmlTagContent

(XmlTag -> String)
Returns XML tag content.

xmlTagName

(XmlTag -> String)
Returns XML tag name.

xmlValidTag

(XmlTag -> Bool)
Checks whether tag is valid.

9.5 Drawing Library (SDL)

This library is currently under development.

The Drawing library is a Wafl graphics library based on SDL2.

It is provided as an additional binary Wafl library libwSDL and must be explicitly included (see section Libraries), as in the following example:

sdl::newDrawing()
.fillRect(...)
...
where {
    sdl = library 'SDL';
}

Function / Type and Description

bmpHeight

(SdlBitmap -> Int)
Get bitmap height.

bmpLoadPng

(String -> SdlBitmap)
Load bitmap image from a file.

bmpSub

(SdlBitmap * Int * Int * Int * Int -> SdlBitmap)
Cut out a part of a bitmap image to a new image.

bmpWidth

(SdlBitmap -> Int)
Get bitmap width.

drawBackColor

(SdlDrawing * Int -> SdlDrawing)
Set background color.

drawBmp

(SdlDrawing * SdlBitmap * Int * Int * Int * Int -> SdlDrawing)
Add bitmap image at given rectangle.

drawBmpAt

(SdlDrawing * SdlBitmap * Int * Int -> SdlDrawing)
Add bitmap image at given position.

drawBmpFull

(SdlDrawing * SdlBitmap -> SdlDrawing)
Add bitmap image at viewport.

drawCircle

(SdlDrawing * Int * Int * Int -> SdlDrawing)
Add a circle to the drawing.

drawClear

(SdlDrawing -> SdlDrawing)
Clears the drawing.

drawEllipse

(SdlDrawing * Int * Int * Int * Int -> SdlDrawing)
Add an ellipse to the drawing.

drawFlush

(SdlDrawing -> SdlDrawing)
Flushes the drawing.

drawFlushClear

(SdlDrawing -> SdlDrawing)
Flushes the drawing and returns an empty drawing.

drawLine

(SdlDrawing * Int * Int * Int * Int -> SdlDrawing)
Add a line to the drawing.

drawLineFrom

(SdlDrawing * Int * Int -> SdlDrawing)
Set ‘last point’.

drawLineFromRel

(SdlDrawing * Int * Int -> SdlDrawing)
Set ‘last point’ relative to the ‘last point’.

drawLineOfPixels

(SdlDrawing * Int * Array[Int] -> SdlDrawing)
Draw a row of pixels.

drawLineTo

(SdlDrawing * Int * Int -> SdlDrawing)
Add a line from ‘last point’ to the given point.

drawLineToRel

(SdlDrawing * Int * Int -> SdlDrawing)
Add a line from ‘last point’ to the relative given point.

drawPoint

(SdlDrawing * Int * Int -> SdlDrawing)
Draw a point.

drawPointC

(SdlDrawing * Int * Int * Int -> SdlDrawing)
Draw a point.

drawRect

(SdlDrawing * Int * Int * Int * Int -> SdlDrawing)
Add a rectangle to the drawing.

drawSaveJpeg

(SdlDrawing * String * Int -> SdlDrawing)
Save to JPEG file.

drawSavePng

(SdlDrawing * String -> SdlDrawing)
Save to PNG file.

drawSetColor

(SdlDrawing * Int -> SdlDrawing)
Set line color for following elements.

drawSetLineWidth

(SdlDrawing * Int -> SdlDrawing)
Set line width.

drawSetLogicalSize

(SdlDrawing * Int * Int -> SdlDrawing)
Set logical display size.

fillRect

(SdlDrawing * Int * Int * Int * Int -> SdlDrawing)
Add a filled rectangle to the drawing.

fillRectC

(SdlDrawing * Int * Int * Int * Int * Int -> SdlDrawing)
Add a filled rectangle, with given color, to the drawing.

newDrawing

( -> SdlDrawing)
Create a new empty drawing.

9.6 Timer Library

This library is currently under development.

The Timer library is a Wafl library for time measurement. It is provided as an additional binary Wafl library libwTimer and must be explicitly included (see section Libraries), as in the following example:

...
.echoTxt( tlib::start(1)$ + '\n' )
...
.echoTxt( tlib::getPartial(1)$ + '\n' )
...
.echoTxt( tlib::getPartial(1)$ + '\n' )
.echoTxt( tlib::getTotal(1)$ + '\n' )

where {
    tlib = library 'Timer';
}

Function / Type and Description

getPartial

(Int -> Float)
Get time duration in seconds from last timer activity.

getTotal

(Int -> Float)
Get time duration in seconds from first timer activity.

start

(Int -> Int)
Start or reset a timer with given id.

9.7 Edlib Library

This library is currently under development.

The Edlib library is a Wafl library for comparison of biological sequences, based on the Edlib C++ library.

It is provided as an additional binary Wafl library libwEdlib and must be explicitly included (see section Libraries).

Function / Type and Description

alignment

(String * String -> String)
Compute string encoded alignment of two strings.

distance

(String * String -> Int)
Compute edit-distance of two strings.

modifications

(String * String -> String)
Compute string encoded modifications positions.

modificationsLst

(String * String -> String)
Compute string encoded modifications positions list.

Wafl Home            Downloads            Wafl Tutorial v.0.6.8 © 2021-2025 Saša Malkov            Open printable version