Functions

Built-in Functions

Function

Description

Assert(x: bool)

Throws an assertion-failed exception if x is false.

BeginTag(q: piece): tag

Returns the begin tag of a piece.

Boolp(x): bool
Charp(x): bool
Funp(x): bool
Intp(x): bool
Listp(x): bool
Methp(x): bool
Objectp(x): bool
Realp(x): bool
Setp(x): bool
Stringp(x): bool
Pagep(x): bool
Piecep(x): bool
Tagp(x): bool
Piecesetp(x): bool

Predicates that check if a value is of a specific type.

Call(cmd: string): string

Executes a shell command and returns the output written to standard out while the command is running. The command string may contain references to variables in lexical scope by writing $var or ${var}. The value of these referenced variables are expanded before the command is executed.

Children(q: piece): pieceset

Returns a piece set consisting of all the direct children elements of q in the markup parse tree, unioned with pieces representing all the text segments in q (excluding all the nested text segments).

Clone(o: object, p: object, ...): object

Makes a new object by copying all the fields of the objects passed as arguments. Fields of p have precedence over fields of o (and so on).

Content(p: page): piece

Returns a piece that encompasses the whole page p.

Content(q: piece): piece

Returns a piece inside q, representing everything that is inside q excluding the begin and end tag of q.

Delete(s: pieceset): nil
Delete(q: piece): nil

Deletes s or q from the page by removing all the pieces from the page data structure.

Elem(p: page): pieceset

Returns all the elements in a page.

Elem(p: page, name: string): pieceset

Returns all the elements in page p with a specific name.

Elem(q: piece): pieceset

Returns all the elements contained (nested) in piece q.

Elem(q: piece, name: string): pieceset

Returns all the elements with a specific name contained in piece q.

EndTag(q: piece): tag

Returns the end tag of a piece.

Error(x, y, z, ...): nil

Prints arguments to standard error output.

ErrorLn(x, y, z, ...): nil

Prints arguments to standard error output followed by end-of-line.

Eval(s: string): any

Evaluates the WebL program coded in string s.

Exec(cmd: string): int

Executes a shell command and returns the exit code returned by the command. The command string may contain references to variables in lexical scope by writing $var or ${var}. The value of these referenced variables are expanded before the command is executed.

Exit(errorcode: int)

Terminates the program with an errorcode.

ExpandCharEntities(p: page,
s: string): string

Expands the character entities (eg. "<", "&") in s to their Unicode character equivalents. The DTD of page p is used for the lookups.

ExpandCharEntities(s: string): string

Expands the character entities (eg. "<", "&") in s to their Unicode character equivalents. The HTML 4.0 DTD is used for the lookups.

DeleteField(o: object, fld): nil

Removes the field fld from the object o. Nothing happens if the field fld does not exist,

First(l: list): any

Returns the first element in a list.

Flatten(s: pieceset): pieceset

Returns a "flattened" piece set (without any overlapping) of all the parts of the page covered by s.

GC(): nil

Explicitly invokes the Java garbage collector.

GetURL(url: string): page

Uses the HTTP GET protocol to fetch the resource identified by the URL.

GetURL(url: string, params: {object,string}): page

The params object/string contains the parameters of a GET that includes a query.

GetURL(url: string, params: {object,string}, headers: object): page

The headers object specifies the additional headers to include in the GET request.

GetURL(url: string, params: {object,string}, headers: object. options: object): page

The options object allows, amongst other functions, the overridng of the MIME type and DTD to be used for parsing the page.

HeadURL(url: string): page

Uses the HTTP HEAD protocol to fetch the resource headers identified by the URL.

HeadURL(url: string, params: {object,string}): page

The params object contains the parameters of the HEAD request.

HeadURL(url: string, params: {object,string}, headers: object): page

The headers object specifies the additional headers to include in the HEAD request.

InsertAfter(t: tag, q: piece): nil
InsertAfter(t: tag, s: pieceset): nil

Inserts a copy of q after the tag t. Inserts copies of the elements of s after the tag t.

InsertBefore(t: tag, q: piece): nil
InsertBefore(t: tag, s: pieceset): nil

Inserts a copy of q before the tag t. Inserts copies of the elements of s before the tag t.

Markup(p: page): string

Turns a page object back into a string.

Markup(q: piece): string

Turns a piece object back into a string.

Name(q: piece): string

Returns the name of a piece.

Native(classname: string): fun

Loads a WebL function1 implemented in Java.

NewNamedPiece(name: string, q: piece): piece

Equivalent to NewNamedPiece(name, BeginTag(q), EndTag(q)).

NewNamedPiece(name: string, t1: tag, t2: tag): piece

Returns a new named piece starting before t1 and ending after t2.

NewPage(s: string, mimetype: string): page

Parses the string s with the mimetype indicated markup parser and returns a page object.

NewPiece(q: piece): piece

Equivalent to NewPiece(BeginTag(q), EndTag(q)).

NewPiece(s: string, mimetype: string): piece

Equivalent to Content(NewPage(s, mimetype)).

NewPiece(t1: tag, t2: tag): piece

Returns a new unnamed piece starting before t1 and ending after t2.

NewPieceSet(s: set): pieceset

Converts a set of pieces into a piece set. Throws an EmptySet exception should s be empty.

NewPieceSet(p: page): pieceset

Returns an empty pieceset associated with with page p.

Page(q: piece): page

Returns the page a piece belongs to.

Page(t: tag): page

Returns the page a tag belongs to.

Para(p: page, paraspec: string): pieceset

Extracts the paragraphs in p according to the paragraph terminator specification paraspec. See Paragraph search

Para(p: piece, paraspec: string): pieceset

Extracts the paragraphs in p according to the paragraph terminator specification paraspec. See Paragraph search

Parent(q: piece): piece

Returns the element in which q is nested (direct parent in the parse tree).

Pat(p: page, regexp: string): pieceset

Returns all the occurrences of a regular expression pattern in page p.

Pat(q: piece, regexp: string): pieceset

Returns all the occurrences of a regular expression pattern located inside the piece q.

PostURL(url: string): page

Uses the HTTP POST protocol to fetch the resource identified by the URL.

PCData(p: page): pieceset

Returns the "parsed character data" of the page. This corresponds to the individual seqences of text on the page, as delimited by markup tags.

PCData(p: piece): pieceset

Returns the "parsed character data" of the piece. This corresponds to the individual seqences of text inside the piece, as delimited by markup tags.

PostURL(url: string, params: {object,string}): page

The params object/string contains the parameters of a POST to fill in a web form.

PostURL(url: string, params: {object,string}, headers: object): page

The headers object specifies the additional headers to include in the POST request.

PostURL(url: string, params: {object,string}, headers: object. options: object): page

The options object allows, amongst other functions, the overridng of the MIME type and DTD to be used for parsing the page.

Pretty(p: page): string

Returns a pretty-printed version of the page.

Pretty(q: piece): string

Returns a pretty-printed version of a piece.

Print(x, y, z, ...): nil

Prints arguments to standard output.

PrintLn(x, y, z, ...): nil

Prints arguments to standard output followed by end-of-line.

ReadLn(): string

Reads a line from standard input (throws away the end-of-line character).

Replace(a: pieceset, b: pieceset): nil

Replaces each piece set of a with copies of all the elements of b.

Rest(l: list): list

Returns a list of all list elements except the first element.

Retry(x): any

Executes expression x and returns its value. In case x throws an exception, x is re-executed as many times as needed until it is successful.

Select(l: list, from: int, to: int): list

Extracts a sublist of l starting at element number from and ending at element number to (exclusive).

Select(s: set, f: fun): set
Select(l: list, f: fun): list
Select(p: pieceset: f: fun): pieceset

Maps sets, lists, and piecesets to sets, lists, and piecesets respectively according to a membership function f. Function f must have a single argument and must return a boolean value indicating whether the actual argument is to be included in the set, list or pieceset.

Select(s: string, from: int, to: int): string

Extracts a substring of s starting at character number from and ending at character number to (exclusive).

Seq(p: page, pattern: string): pieceset

Matches all the occurrences of a sequence of elements identified by pattern. See PCData search

Seq(p: piece, pattern: string): pieceset

Matches all the occurrences of a sequence of elements identified by pattern inside the piece p. See PCData search

Sign(x: int): int
Sign(x: real): int

Returns -1, 0, +1 if x < 0, x = 0, and x > 0 respectively.

Size(l: list): int

Returns the number of elements in a list.

Size(s: set): int

Returns the number of elements in a set.

Size(s: string): int

Returns the number of characters in a string.

Size(p: pieceset): int

Returns the number of pieces belonging to p.

Sleep(ms: int): nil

Suspends thread execution for the specified number of milliseconds.

Sort(l: list, f: fun): list

Sorts the elements of l according to the comparison function f. The function f needs to take two formal arguments and return -1, 0, or +1 if the actual arguments are less, equal, or more than each other.

Stall()

Program goes to sleep forever.

Text(p: page): string

Returns the text (sans tags) of a page.

Text(q: piece): string

Returns the text (sans tags) of a piece.

Text(q: piece, insertspaces: boolean): string

Returns the text (sans tags) of a piece. When insertspaces is true, each HTML tag is mapped into a space and inserted into the result string (inline tags like "b", "i", "em", etc. are ignored and not mapped into spaces). This option is useful to correctly identify word boundaries, for example to prevent words flowing together in a case like "<li>wordA</li><li>wordB</li>".

Throw(o: object)

Generates an exception.

Time(x): int

Returns the time (in milliseconds) it takes to evaluate the expression x.

Timeout(ms: int, x): any

Performs the expression x and returns its value. If the evaluation takes more than the specified amount of time (in milliseconds), an exception is thrown instead.

ToChar(c: char): char

No operation.

ToChar(i: int): char

Converts an integer to the equivalent Unicode character.

ToInt(c: char): int

Returns the Unicode character number of a char.

ToInt(i: int): int

No operation.

ToInt(r: real): int

Rounds a real value down to an integer.

ToInt(s: string): int

Converts a string to the numeric equivalent.

ToList(s: set): list
ToList(l: list): list
ToList(s: string): list
ToList(o: object): list
ToList(p: pieceset): list

Enumerates all the elements of the argument and returns a list. (See Every Statement)

ToReal(c: char): real

Same as ToReal(ToInt(c)).

ToReal(i: int): real

Converts an integer to a real.

ToReal(r: real): real

No operation.

ToReal(s: string): real

Converts a string to a real value.

ToSet(s: set): set
ToSet(l: list): set
ToSet(s: string): set
ToSet(o: object): set
ToSet(p: pieceset): set

Enumerates all the elements of the argument and returns a set. (See Every Statement)

ToString(x): string

Converts a value to its string representation.

Trap(x):object

Executes x and returns the exception object that was caught. In case no exception is thrown in x, nil is returned. In addition, the exception object contains a field trace that has extra information why the exception occurred. This information is useful for logging unexpected exception events in your WebL programs.

Type(x): string

Returns the type of x (nil, int, real, bool, char, string, meth, fun, set, list, object, page, piece, pieceset, tag).


1. The class indicated must be a subclass of webl.lang.expr.AbstractFunExpr


Up Previous Next