Saltearse al contenido

Guía del lenguaje

lang.wlk

Class Exception

Base class for all Exceptions. Every exception and its subclasses

indicates conditions that a reasonable application might want to catch.

since 1.0

Estado

Atributo WollokDoc
const property message

specified detail message.

const property cause

specified cause

Comportamiento

override native
initialize()

Documentation not found

printStackTrace()

Prints this exception and its backtrace to the console

getStackTraceAsString()

Documentation not found

printStackTrace(printer)

Documentation not found

printStackTraceWithPrefix(prefix, printer)

Documentation not found

createStackTraceElement(contextDescription, location)

Documentation not found

native
getFullStackTrace()

Documentation not found

native
getStackTrace()

Provides programmatic access to the stack trace information

printed by printStackTrace().

override
==(other)

Overrides the behavior to compare exceptions

Class StackOverflowException

Thrown when a stack overflow occurs because an application recurses too deeply.

since 1.5.1

Class ElementNotFoundException

An exception that is thrown when a specified element cannot be found

Class DomainException

An exception that is thrown for domain purpose

Estado

Atributo WollokDoc
const property source

Documentation not found

Class EvaluationError

(added by wollok-ts) An exception thrown whenever the interpreter fails to evaluate an expression

Class MessageNotUnderstoodException

An exception that is thrown when an object cannot understand a certain message

Class StackTraceElement

An element in a stack trace, represented by a context and a location

of a method where a message was sent

Estado

Atributo WollokDoc
const property contextDescription

Documentation not found

const property location

Documentation not found

Class Object

Representation of Wollok Object

Class Object is the root of the class hierarchy.

Every class has Object as a superclass.

since 1.0

Comportamiento

initialize()

Documentation not found

native
identity()

Documentation not found

native
kindName()

Object description in english/spanish/... (depending on i18n configuration)

"2".kindName()  => Answers "a String"
2.kindName()    => Answers "a Integer"
<strong>private</strong>
"2".kindName()  => Answers "a String"
2.kindName()    => Answers "a Integer"
<strong>private</strong>
native
className()

Full name of Wollok object class

private

==(other)

Tells whether self object is "equal" to the given object

This method implements an equivalence relation on non-null object references:

- It is reflexive: for any non-null reference value x, x == x should return true.

- It is symmetric: for any non-null reference values x and y, x == y

should return true if and only if y == x returns true.

- It is transitive: for any non-null reference values x, y, and z,

if x == y returns true and y == z returns true,

then x == z should return true.

- It is consistent: for any non-null reference values x and y, multiple invocations

of x == y consistently return true or consistently return false,

provided no information used in equals comparisons on the objects is modified.

- For any non-null reference value x, x == null should return false.

The default behavior compares them in terms of identity (===)

!=(other)

Documentation not found

===(other)

Documentation not found

!==(other)

Tells whether self object is not identical (the same) to the given one.

See === message.

equals(other)

Documentation not found

->(other)

Documentation not found

toString()

Documentation not found

shortDescription()

Documentation not found

printString()

Provides a visual representation of Wollok Object

By default, same as toString but can be overridden

like in String

messageNotUnderstood(messageName, parameters)

private

native
generateDoesNotUnderstandMessage(target, messageName, parametersSize)

Documentation not found

error(aMessage)

Builds an exception with a message

native
checkNotNull(value, message)

Documentation not found

Singleton void

Representation for methods that only have side effects

Class Pair

Representation of a Key/Value Association.

It is also useful if you want to model a Point.

Estado

Atributo WollokDoc
const property x

Documentation not found

const property y

Documentation not found

Comportamiento

key()

Documentation not found

value()

Documentation not found

override
==(other)

Documentation not found

override
toString()

Documentation not found

Class Collection

The root class in the collection hierarchy.

A collection represents a group of objects, known as its elements.

Comportamiento

max(closure)

Answers the element that is considered to be/have the maximum value.

The criteria is given by a closure that receives a single element

as input (one of the element). The closure must return a comparable

value (something that understands the >, >= messages).

If collection is empty, an ElementNotFound exception is thrown.

["a", "ab", "abc", "d" ].max({ e => e.length() })
=> Answers "abc"
[].max({ e => e.length() })
=> Throws error, list must not be empty
["a", "ab", "abc", "d" ].max({ e => e.length() })
=> Answers "abc"
[].max({ e => e.length() })
=> Throws error, list must not be empty
max()

Documentation not found

maxIfEmpty(toComparableClosure, emptyCaseClosure)

Answers the element that is considered to be/have the maximum value,

or applies a closure if the collection is empty.

The criteria is given by a closure that receives a single element

as input (one of the element). The closure must return a comparable

value (something that understands the >, >= messages).

The closure to execute when the collection is empty is given as a second

argument.

["a", "ab", "abc", "d" ].maxIfEmpty({ e => e.length() }, { "default" })
=> Answers "abc"
[].maxIfEmpty({ e => e.length() }, { "default" })
=> Answers "default"
["a", "ab", "abc", "d" ].maxIfEmpty({ e => e.length() }, { "default" })
=> Answers "abc"
[].maxIfEmpty({ e => e.length() }, { "default" })
=> Answers "default"
maxIfEmpty(emptyCaseClosure)

Documentation not found

min(closure)

Answers the element that is considered to be/have the minimum value.

The criteria is given by a closure that receives a single element

as input (one of the element). The closure must return a comparable

value (something that understands the <, <= messages).

["ab", "abc", "hello", "wollok world"].min({ e => e.length() })
=>  Answers "ab"
[].min({ e => e.length() })
=> Throws error, list must not be empty
["ab", "abc", "hello", "wollok world"].min({ e => e.length() })
=>  Answers "ab"
[].min({ e => e.length() })
=> Throws error, list must not be empty
min()

Documentation not found

minIfEmpty(toComparableClosure, emptyCaseClosure)

Answers the element that is considered to be/have the minimum value,

or applies a closure if the collection is empty.

The criteria is given by a closure that receives a single element

as input (one of the element). The closure must return a comparable

value (something that understands the >, >= messages).

The closure to execute when the collection is empty is given as a second

argument.

["ab", "abc", "hello", "wollok world"].minIfEmpty({ e => e.length() }, { "default" })
=>  Answers "ab"
[].minIfEmpty({ e => e.length() }, { "default" })
=> Answers "default"
["ab", "abc", "hello", "wollok world"].minIfEmpty({ e => e.length() }, { "default" })
=>  Answers "ab"
[].minIfEmpty({ e => e.length() }, { "default" })
=> Answers "default"
minIfEmpty(emptyCaseClosure)

Documentation not found

absolute(closure, criteria, emptyCaseClosure)

Documentation not found

uniqueElement()

Documentation not found

+(elements)

Documentation not found

addAll(elements)

Documentation not found

removeAll(elements)

Documentation not found

removeAllSuchThat(closure)

Documentation not found

isEmpty()

Documentation not found

validateNotEmpty(operation)

Documentation not found

forEach(closure)

Documentation not found

all(predicate)

Documentation not found

any(predicate)

Documentation not found

find(predicate)

Documentation not found

findOrDefault(predicate, value)

Documentation not found

native
findOrElse(predicate, continuation)

Answers the element of self collection that satisfies a given condition,

or the the result of evaluating the given continuation.

If more than one element satisfies the condition then it depends on the

specific collection class which element will be returned.

returns the element that complies the condition or the result

of evaluating the continuation

users.findOrElse({ user => user.name() == "Cosme Fulanito" }, { homer })
[1, 3, 5].findOrElse({ number => number.even() }, { 6.max(4) }) => Answers 6
[].findOrElse({ number => number.even() }, { false })           => Answers false
users.findOrElse({ user => user.name() == "Cosme Fulanito" }, { homer })
[1, 3, 5].findOrElse({ number => number.even() }, { 6.max(4) }) => Answers 6
[].findOrElse({ number => number.even() }, { false })           => Answers false
count(predicate)

Counts all elements of self collection that satisfies a given condition

The condition is a closure argument that takes a single element and

answers a number.

returns an integer number

plants.count { plant => plant.hasFlowers() }
#{1, 2, 3, 4, 5}.count { number => number.odd() }  => Answers 3
#{}.count { number => number.odd() }               => Answers 0
plants.count { plant => plant.hasFlowers() }
#{1, 2, 3, 4, 5}.count { number => number.odd() }  => Answers 3
#{}.count { number => number.odd() }               => Answers 0
occurrencesOf(element)

Documentation not found

sum(closure)

Collects the sum of each value for all elements.

This is similar to call a map {} to transform each element into a

number object and then adding all those numbers.

The condition is a closure argument that takes a single element and

answers a boolean value.

returns an integer

const totalNumberOfFlowers = plants.sum{ plant => plant.numberOfFlowers() }
[].sum { employee => employee.salary() }   => Answers 0
const totalNumberOfFlowers = plants.sum{ plant => plant.numberOfFlowers() }
[].sum { employee => employee.salary() }   => Answers 0
sum()

Documentation not found

map(closure)

Answers a new collection that contains the result of transforming

each of self collection's elements using a given closure.

The condition is a closure argument that takes a single element

and answers an object.

returns another list

const ages = users.map({ user => user.age() })
[1, 2, 3].map { number => number.odd() }  => Answers [true, false, true]
[].map { number => number.odd() }         => Answers []
const ages = users.map({ user => user.age() })
[1, 2, 3].map { number => number.odd() }  => Answers [true, false, true]
[].map { number => number.odd() }         => Answers []
flatMap(closure)

Documentation not found

filter(closure)

Documentation not found

contains(element)

Documentation not found

flatten()

Documentation not found

override
toString()

Documentation not found

abstract
toStringPrefix()

Documentation not found

abstract
toStringSuffix()

Documentation not found

override
printString()

Documentation not found

abstract
asList()

Documentation not found

abstract
asSet()

Documentation not found

copy()

Documentation not found

copyWithout(elementToRemove)

Documentation not found

copyWith(elementToAdd)

Documentation not found

sortedBy(closure)

Documentation not found

abstract
newInstance()

Documentation not found

anyOne()

Documentation not found

add(element)

Documentation not found

remove(element)

Documentation not found

fold(element, closure)

Documentation not found

size()

Documentation not found

abstract
clear()

Documentation not found

join(separator)

Documentation not found

join()

Documentation not found

Singleton collection

Builder object for collections.

It compensates for the lack of vararg constructors.

Comportamiento

list(elements)

Documentation not found

set(elements)

Documentation not found

Class Set

A collection that contains no duplicate elements.

It models the mathematical set abstraction.

A Set guarantees no order of elements.

Note: Great care must be exercised if mutable objects are used as set elements.

The behavior of a set is not specified if the value of an object is changed in

a manner that affects equals comparisons while the object is an element in the set.

A special case of this prohibition is that it is not permissible for a set to contain

itself as an element.

since 1.3

Comportamiento

override
newInstance()

Documentation not found

override
toStringPrefix()

Documentation not found

override
toStringSuffix()

Documentation not found

override
asList()

Documentation not found

override
asSet()

Documentation not found

override native
anyOne()

Documentation not found

union(another)

Answers a new Set with the elements of both self and another collection.

#{1, 2}.union(#{5, 2})   => #{1, 2, 5}
#{}.union(#{3})          => #{3}
<strong>returns</strong> a Set
#{1, 2}.union(#{5, 2})   => #{1, 2, 5}
#{}.union(#{3})          => #{3}
<strong>returns</strong> a Set
intersection(another)

Documentation not found

difference(another)

Answers a new Set with the elements of self that don't exist in another collection

#{1, 2}.difference(#{5, 2}) => #{1}
#{3}.difference(#{})        => #{3}
<strong>returns</strong> a Set
#{1, 2}.difference(#{5, 2}) => #{1}
#{3}.difference(#{})        => #{3}
<strong>returns</strong> a Set
override native
fold(initialValue, closure)

Reduce a collection to a certain value, beginning with a seed or initial value.

#{1, 9, 3, 8}.fold(0, {acum, each => acum + each})
=> Answers 21, the sum of all elements
#{}.fold(0, {acum, each => acum + each})
=> Answers 0, the seed.
var numbers = #{3, 2, 9, 1, 7}
numbers.fold(numbers.anyOne(), { acum, number => acum.max(number) })
=> Answers 9, the maximum of all elements
#{1, 9, 3, 8}.fold(0, {acum, each => acum + each})
=> Answers 21, the sum of all elements
#{}.fold(0, {acum, each => acum + each})
=> Answers 0, the seed.
var numbers = #{3, 2, 9, 1, 7}
numbers.fold(numbers.anyOne(), { acum, number => acum.max(number) })
=> Answers 9, the maximum of all elements
override native
filter(closure)

Answers a new set with the elements meeting

a given condition. The condition is a closure argument that

takes a single element and answers a boolean.

#{1, 2, 3, 4, 5}.filter { number => number.even() }   => Answers #{2, 4}
#{}.filter { number => number.even() }                => Answers #{}
<strong>see</strong> Collection#filter(closure)
#{1, 2, 3, 4, 5}.filter { number => number.even() }   => Answers #{2, 4}
#{}.filter { number => number.even() }                => Answers #{}
<strong>see</strong> Collection#filter(closure)
override native
max()

Answers the element that represents the maximum value in the collection.

The criteria is by direct comparison of the elements.

If set is empty, an ElementNotFound exception is thrown.

#{1, 9, 3, 15}.max()  =>  Answers 15
#{}.max()             =>  Throws error, set must not be empty
<strong>see</strong> Collection#max()
#{1, 9, 3, 15}.max()  =>  Answers 15
#{}.max()             =>  Throws error, set must not be empty
<strong>see</strong> Collection#max()
override native
findOrElse(predicate, continuation)

Tries to find an element in a collection (based on a closure) or

applies a continuation closure.

#{1, 9, 3, 8}.findOrElse({ n => n.even() }, { 100 })  => Answers  8
#{1, 5, 3, 7}.findOrElse({ n => n.even() }, { 100 })  => Answers  100
#{1, 9, 3, 8}.findOrElse({ n => n.even() }, { 100 })  => Answers  8
#{1, 5, 3, 7}.findOrElse({ n => n.even() }, { 100 })  => Answers  100
override native
add(element)

Adds the specified element to this set if it is not already present.

const set = #{}
set.add(3)   => set = #{3}
set.add(2)   => set = #{2, 3}
set.add(2)   => set = #{2, 3}, second add produces no effect
const set = #{}
set.add(3)   => set = #{3}
set.add(2)   => set = #{2, 3}
set.add(2)   => set = #{2, 3}, second add produces no effect
native
unsafeAdd(element)

private

override native
remove(element)

Removes the specified element from this set if it is present.

const set = #{2, 3}
set.remove(3) => set = #{2}
set.remove(4) => set = #{2}, remove operation produces no effect
const set = #{2, 3}
set.remove(3) => set = #{2}
set.remove(4) => set = #{2}, remove operation produces no effect
override native
size()

Answers the number of elements in this set (its cardinality).

#{2, 3}.size()   => Answers 2
#{}.size()       => Answers 0
#{2, 3}.size()   => Answers 2
#{}.size()       => Answers 0
override native
clear()

Removes all of the elements from this set. This is a side effect operation.

const set = #{2, 3}
set.clear()         => set = #{}
const set = #{2, 3}
set.clear()         => set = #{}
override native
join(separator)

Answers the concatenated string representation of the elements in the given set.

You can pass an optional character as an element separator (default is ",")

#{1, 5, 3, 7}.join(":")                   => Answers "1:5:3:7"
#{"you","will","love","wollok"}.join(" ") => Answers "love will wollok you"
#{}.join(",")                             => Answers ""
#{1, 5, 3, 7}.join(":")                   => Answers "1:5:3:7"
#{"you","will","love","wollok"}.join(" ") => Answers "love will wollok you"
#{}.join(",")                             => Answers ""
override native
join()

Answers the concatenated string representation of the elements in the given set

with default element separator (",")

#{"you","will","love","wollok"}.join()    => Answers "love,will,wollok,you"
#{"you","will","love","wollok"}.join()    => Answers "love,will,wollok,you"
override native
contains(other)

Answers whether this collection contains the specified element.

#{}.contains(3)        => Answers false
#{1, 2, 3}.contains(2) => Answers true
#{1, 2, 3}.contains(4) => Answers false
<strong>see</strong> List#contains(other)
#{}.contains(3)        => Answers false
#{1, 2, 3}.contains(2) => Answers true
#{1, 2, 3}.contains(4) => Answers false
<strong>see</strong> List#contains(other)
override native
==(other)

Two sets are equals if they have the same elements, no matter

the order.

#{} == #{}         => Answers true
#{1, 2} == #{2, 1} => Answers true
#{3, 2} == #{2, 1} => Answers false
#{} == #{}         => Answers true
#{1, 2} == #{2, 1} => Answers true
#{3, 2} == #{2, 1} => Answers false

Class List

An ordered collection (also known as a sequence).

You iterate the list the same order elements are inserted.

The user can access elements by their integer index (position in the list).

A List can contain duplicate elements.

since 1.3

Comportamiento

native
get(index)

Documentation not found

override
newInstance()

Creates a new list

override
anyOne()

Documentation not found

first()

Documentation not found

head()

Synonym for first method

last()

Documentation not found

override
toStringPrefix()

Documentation not found

override
toStringSuffix()

Documentation not found

override
asList()

Documentation not found

override
asSet()

Converts a collection to a set (removing duplicates if necessary)

[1, 2, 3].asSet()       => Answers #{1, 2, 3}
[].asSet()              => Answers #{}
[1, 2, 1, 1, 2].asSet() => Answers #{1, 2}
#{1, 2, 3}.asSet()      => Answers #{1, 2, 3}
#{}.asSet()             => Answers #{}
<strong>see</strong> Set
[1, 2, 3].asSet()       => Answers #{1, 2, 3}
[].asSet()              => Answers #{}
[1, 2, 1, 1, 2].asSet() => Answers #{1, 2}
#{1, 2, 3}.asSet()      => Answers #{1, 2, 3}
#{}.asSet()             => Answers #{}
<strong>see</strong> Set
subList(start)

Documentation not found

subList(start, end)

Documentation not found

native
sortBy(closure)

Documentation not found

take(n)

Takes first n elements of a list.

[1,9,2,3].take(5)  ==> Answers [1, 9, 2, 3]
[1,9,2,3].take(2)  ==> Answers [1, 9]
[1,9,2,3].take(-2) ==> Answers []
[].take(2)         ==> Answers []
[1,9,2,3].take(5)  ==> Answers [1, 9, 2, 3]
[1,9,2,3].take(2)  ==> Answers [1, 9]
[1,9,2,3].take(-2) ==> Answers []
[].take(2)         ==> Answers []
drop(n)

Documentation not found

reverse()

Documentation not found

override native
filter(closure)

Answers a new list with the elements meeting

a given condition. The condition is a closure argument that

takes a single element and answers a boolean.

[1, 2, 3, 4, 5].filter { number => number.even() }   => Answers [2, 4]
[].filter { number => number.even() }                => Answers []
<strong>see</strong> Collection#filter(closure)
[1, 2, 3, 4, 5].filter { number => number.even() }   => Answers [2, 4]
[].filter { number => number.even() }                => Answers []
<strong>see</strong> Collection#filter(closure)
override native
contains(obj)

Answers whether this collection contains the specified element.

[].contains(3)        => Answers false
[1, 2, 3].contains(2) => Answers true
[1, 2, 3].contains(4) => Answers false
<strong>see</strong> Collection#contains(obj)
[].contains(3)        => Answers false
[1, 2, 3].contains(2) => Answers true
[1, 2, 3].contains(4) => Answers false
<strong>see</strong> Collection#contains(obj)
override native
max()

Answers the element that represents the maximum value in the collection.

The criteria is by direct comparison of the elements (they must be sortable).

If collection is empty, an ElementNotFound exception is thrown.

[11, 1, 4, 8, 3, 15, 6].max() =>  Answers 15
[].max()                      =>  Throws error, list must not be empty
<strong>see</strong> Collection#max()
[11, 1, 4, 8, 3, 15, 6].max() =>  Answers 15
[].max()                      =>  Throws error, list must not be empty
<strong>see</strong> Collection#max()
override native
fold(initialValue, closure)

Reduce a collection to a certain value, beginning with a seed or initial value

[1, 9, 3, 8].fold(0, {acum, each => acum + each})
=> Answers 21, the sum of all elements
[].fold(0, {acum, each => acum + each})
=> Answers 0, the seed.
const numbers = [3, 2, 9, 1, 7]
numbers.fold(numbers.anyOne(), { acum, number => acum.max(number) })
=> Answers 9, the maximum of all elements
[1, 9, 3, 8].fold(0, {acum, each => acum + each})
=> Answers 21, the sum of all elements
[].fold(0, {acum, each => acum + each})
=> Answers 0, the seed.
const numbers = [3, 2, 9, 1, 7]
numbers.fold(numbers.anyOne(), { acum, number => acum.max(number) })
=> Answers 9, the maximum of all elements
override native
findOrElse(predicate, continuation)

Finds the first element matching the boolean closure,

or evaluates the continuation block closure if no element is found

[1, 9, 3, 8].findOrElse({ n => n.even() }, { 100 })  => Answers  8
[1, 5, 3, 7].findOrElse({ n => n.even() }, { 100 })  => Answers  100
[1, 9, 3, 8].findOrElse({ n => n.even() }, { 100 })  => Answers  8
[1, 5, 3, 7].findOrElse({ n => n.even() }, { 100 })  => Answers  100
override native
add(element)

Adds the specified element as last one

const list = []
list.add(3)   => list = [3]
list.add(2)   => list = [3, 2]
list.add(2)   => list = [3, 2, 2]
const list = []
list.add(3)   => list = [3]
list.add(2)   => list = [3, 2]
list.add(2)   => list = [3, 2, 2]
override native
remove(element)

Removes an element in this list, if it is present.

const list = [2, 3]
list.remove(3) => list = [2]
list.remove(4) => list = [2], remove operation produces no effect
const list = [2, 3]
list.remove(3) => list = [2]
list.remove(4) => list = [2], remove operation produces no effect
override native
size()

Answers the number of elements

[2, 3].size()   => Answers 2
[].size()       => Answers 0
[2, 3].size()   => Answers 2
[].size()       => Answers 0
override native
clear()

Removes all of the mappings from this Dictionary.

This is a side effect operation.

const list = [2, 3]
list.clear()     => list = []
const list = [2, 3]
list.clear()     => list = []
override native
join(separator)

Answers the concatenated string representation of the elements in the given set.

You can pass an optional character as an element separator (default is ",")

[1, 5, 3, 7].join(":") => Answers "1:5:3:7"
["you","will","love","wollok"].join(" ") => Answers "you will love wollok"
[1, 5, 3, 7].join(":") => Answers "1:5:3:7"
["you","will","love","wollok"].join(" ") => Answers "you will love wollok"
override native
join()

Answers the concatenated string representation of the elements in the given set,

using default element separator (",")

["you","will","love","wollok"].join()    => Answers "you,will,love,wollok"
["you","will","love","wollok"].join()    => Answers "you,will,love,wollok"
override native
==(other)

A list is == another list if all elements are equal (defined by == message)

[] == []         => Answers true
[1, 2] == [2, 1] => Answers false
[1, 2] == [1, 2] => Answers true
[] == []         => Answers true
[1, 2] == [2, 1] => Answers false
[1, 2] == [1, 2] => Answers true
native
withoutDuplicates()

Answers the list without duplicate elements. Preserves order of elements.

[1, 3, 1, 5, 1, 3, 2, 5].withoutDuplicates() => Answers [1, 3, 5, 2]

[].withoutDuplicates() => Answers []

randomize()

Shuffles the order of the elements in the list.

This is a side effect operation.

const list = [1, 2 ,3]
list.randomize()     => list = [2, 1, 3]
const list = [1, 2 ,3]
list.randomize()     => list = [2, 1, 3]
randomized()

Documentation not found

Class Dictionary

Represents a set of key -> values

Comportamiento

override native
initialize()

Documentation not found

native
put(_key, _value)

Adds or updates a value based on a key.

If key is not present, a new value is added.

If key is present, value is updated.

This is a side effect operation.

const phones = new Dictionary()
phones.put("4004-4004", rolo)
=> phones == a Dictionary ["4004-4004" -> rolo]
const phones = new Dictionary()
phones.put("4004-4004", rolo)
=> phones == a Dictionary ["4004-4004" -> rolo]
native
basicGet(_key)

Answers the value to which the specified key is mapped,

or null if this Dictionary contains no mapping for the key.

phones.basicGet("4004-4004")  => Answers rolo
phones.basicGet("4004-4005")  => Answers null
phones.basicGet("4004-4004")  => Answers rolo
phones.basicGet("4004-4005")  => Answers null
getOrElse(_key, _closure)

Answers the value to which the specified key is mapped,

or evaluates a non-parameter closure otherwise.

phones.getOrElse("4004-4004", { 0 })  => Answers rolo
phones.getOrElse("4004-4005", { 0 })  => Answers 0
phones.getOrElse("4004-4004", { 0 })  => Answers rolo
phones.getOrElse("4004-4005", { 0 })  => Answers 0
get(_key)

Documentation not found

size()

Answers the number of key-value mappings in this Dictionary.

phones.size()           => Answers 1
new Dictionary().size() => Answers 0
phones.size()           => Answers 1
new Dictionary().size() => Answers 0
isEmpty()

Answers whether the dictionary has no elements

phones.isEmpty()           => Answers false
new Dictionary().isEmpty() => Answers true
phones.isEmpty()           => Answers false
new Dictionary().isEmpty() => Answers true
containsKey(_key)

Documentation not found

containsValue(_value)

Answers whether if this Dictionary maps one or more keys to the specified value.

const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.containsValue(2)          => Answers true
numbers.containsValue(5)          => Answers false
new Dictionary().containsValue(3) => Answers false
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.containsValue(2)          => Answers true
numbers.containsValue(5)          => Answers false
new Dictionary().containsValue(3) => Answers false
native
remove(_key)

Removes the mapping for a key from this Dictionary if it is present.

If key is not present nothing happens.

This is a side effect operation.

const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.remove("one")   => numbers is a dictionary ("two" -> 2)
numbers.remove("three") => nothing happens
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.remove("one")   => numbers is a dictionary ("two" -> 2)
numbers.remove("three") => nothing happens
native
keys()

Answers a list of the keys contained in this Dictionary.

const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.keys()   => ["one", "two"]
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.keys()   => ["one", "two"]
native
values()

Answers a list of the values contained in this Dictionary.

const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.values()   => [1, 2]
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.values()   => [1, 2]
native
forEach(closure)

Performs the given action for each entry in this Dictionary

until all entries have been processed or the action throws an exception.

Expected closure with two parameters: the first associated with key and

second with value.

mapaTelefonos.forEach({ k, v => result += k.size() + v.size() })
mapaTelefonos.forEach({ k, v => result += k.size() + v.size() })
native
clear()

Removes all of the mappings from this Dictionary.

This is a side effect operation.

const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.clear()  => phones == empty dictionary
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.clear()  => phones == empty dictionary
override
toString()

String representation of a Dictionary

const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
=> Answers a Dictionary ["one" -> 1, "two" -> 2]
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
=> Answers a Dictionary ["one" -> 1, "two" -> 2]
override
==(other)

Documentation not found

Class Number

In Wollok we have numbers as an immutable representation. You can customize

how many decimals you want to work with, and printing strategies. So

number two could be printed as "2", "2,00000", "2,000", etc.

Coercing strategy for numbers can be

1) rounding up: 2,3258 using 3 decimals will result in 2,326

2) rounding down or truncation: 2,3258 using 3 decimals will

result in 2,325

3) not allowed: 2,3258 using 3 decimals will throw an exception

since decimals exceeds maximum allowed

(unification between Double and Integer in a single Number class)

since 1.3

noInstantiate

Comportamiento

native
coerceToInteger()

private

Applies coercing strategy to integer. If it is an integer, nothing happens.

Otherwise, if it is a decimal, defined coercing algorithm is applied

(see definition of class Number)

native
coerceToPositiveInteger()

private

see coerceToInteger

Applies coercing strategy to integer. And throws exception if it is negative.

override native
===(other)

Two references are identical if they are the same number

native
+(other)

Documentation not found

native
-(other)

Documentation not found

native
*(other)

Documentation not found

native
/(other)

Documentation not found

div(other)

Integer division between self and other

8.div(3)      ==> Answers 2
15.div(5)     ==> Answers 3
8.2.div(3.3)  ==> Answers 2
8.div(3)      ==> Answers 2
15.div(5)     ==> Answers 3
8.2.div(3.3)  ==> Answers 2
native
**(other)

Documentation not found

native
%(other)

Answers remainder of division between self and other

override native
toString()

String representation of self number

..(end)

Builds a Range between self and end

1..4       Answers ==> a new Range object from 1 to 4
1..4       Answers ==> a new Range object from 1 to 4
native
>(other)

Documentation not found

native
<(other)

Documentation not found

>=(other)

Documentation not found

<=(other)

Documentation not found

native
abs()

Documentation not found

native
invert()

Inverts sign of self

3.invert()      ==> Answers -3
(-2).invert()   ==> Answers 2 (be careful with parentheses)
3.2.invert()    ==> -3.2
(-2.4).invert() ==> 2.4 (be careful with parentheses)
3.invert()      ==> Answers -3
(-2).invert()   ==> Answers 2 (be careful with parentheses)
3.2.invert()    ==> -3.2
(-2.4).invert() ==> 2.4 (be careful with parentheses)
max(other)

Answers the greater number between two

5.max(8)    ==> Answers 8
5.max(8)    ==> Answers 8
min(other)

Documentation not found

limitBetween(limitA, limitB)

Documentation not found

between(min, max)

Documentation not found

squareRoot()

Documentation not found

square()

Documentation not found

even()

Answers whether self is an even number

(divisible by 2, mathematically 2k).

Self must be an integer value

odd()

Documentation not found

rem(other)

Documentation not found

stringValue()

Documentation not found

native
roundUp(_decimals)

Rounds up self up to a certain amount of decimals.

Amount of decimals must be a positive and integer value.

1.223445.roundUp(3)  ==> 1.224
-1.223445.roundUp(3) ==> -1.224
14.6165.roundUp(3)   ==> 14.617
5.roundUp(3)         ==> 5
1.223445.roundUp(3)  ==> 1.224
-1.223445.roundUp(3) ==> -1.224
14.6165.roundUp(3)   ==> 14.617
5.roundUp(3)         ==> 5
native
truncate(_decimals)

Truncates self up to a certain amount of decimals.

Amount of decimals must be a positive and integer value.

1.223445.truncate(3) ==> 1.223
14.6165.truncate(3)  ==> 14.616
-14.6165.truncate(3) ==> -14.616
5.truncate(3)        ==> 5
1.223445.truncate(3) ==> 1.223
14.6165.truncate(3)  ==> 14.616
-14.6165.truncate(3) ==> -14.616
5.truncate(3)        ==> 5
native
randomUpTo(max)

Answers a random number between self and max

roundUp()

Answers the next integer greater than self

13.224.roundUp()  ==> 14
-13.224.roundUp() ==> -14
15.942.roundUp()  ==> 16
13.224.roundUp()  ==> 14
-13.224.roundUp() ==> -14
15.942.roundUp()  ==> 16
native
round()

Returns the value of a number rounded to the nearest integer.

native
gcd(other)

greater common divisor.

Both self and "other" parameter are coerced to be integer values.

8.gcd(12) ==> Answers 4
5.gcd(10) ==> Answers 5
8.gcd(12) ==> Answers 4
5.gcd(10) ==> Answers 5
lcm(other)

least common multiple.

Both self and "other" parameter are coerced to be integer values.

3.lcm(4)  ==> Answers 12
6.lcm(12) ==> Answers 12
3.lcm(4)  ==> Answers 12
6.lcm(12) ==> Answers 12
digits()

Documentation not found

native
isInteger()

Documentation not found

isPrime()

Answers whether self is a prime number,

like 2, 3, 5, 7, 11 ...

Self must be an integer positive value

times(action)

Documentation not found

plus()

Documentation not found

Class String

Strings are constant;

their values cannot be changed after they are created.

noInstantiate

Comportamiento

native
length()

Answers the number of elements

charAt(index)

Answers the char value at the specified index. An index ranges

from 0 to length() - 1. The first char value of the sequence is

at index 0, the next at index 1, and so on, as for array indexing.

Parameter index must be a positive integer value.

+(other)

Documentation not found

native
concat(other)

Concatenates the specified string to the end of this string. Same as +.

"cares".concat("s") => Answers "caress"
"cares".concat("s") => Answers "caress"
native
startsWith(prefix)

Tests if this string starts with the specified prefix.

It is case sensitive.

"mother".startsWith("moth")  ==> Answers true
"mother".startsWith("Moth")  ==> Answers false
"mother".startsWith("moth")  ==> Answers true
"mother".startsWith("Moth")  ==> Answers false
native
endsWith(suffix)

Tests if this string ends with the specified suffix.

It is case sensitive.

see startsWith

native
indexOf(other)

Answers the index within this string of the first occurrence

of the specified character.

If character is not present, Answers -1

"pototo".indexOf("o")         ==> Answers 1
"unpredictable".indexOf("o")  ==> Answers -1
"pototo".indexOf("o")         ==> Answers 1
"unpredictable".indexOf("o")  ==> Answers -1
native
lastIndexOf(other)

Answers the index within this string of the last

occurrence of the specified character.

If character is not present, Answers -1

"pototo".lastIndexOf("o")         ==> Answers 5
"unpredictable".lastIndexOf("o")  ==> Answers -1
"pototo".lastIndexOf("o")         ==> Answers 5
"unpredictable".lastIndexOf("o")  ==> Answers -1
native
toLowerCase()

Converts all of the characters in this String to lower case

"Fer".toLowerCase()  ==> Answers "fer"
"".toLowerCase()     ==> Answers ""
"Fer".toLowerCase()  ==> Answers "fer"
"".toLowerCase()     ==> Answers ""
native
toUpperCase()

Converts all of the characters in this String to upper case

"Fer".toUpperCase()  ==> Answers "FER"
"".toUpperCase()     ==> Answers ""
"Fer".toUpperCase()  ==> Answers "FER"
"".toUpperCase()     ==> Answers ""
native
trim()

Answers a string whose value is this string,

with any leading and trailing whitespace removed.

"   emptySpace  ".trim()  ==> "emptySpace"
"   emptySpace  ".trim()  ==> "emptySpace"
native
reverse()

Answers a string reversing this string,

so that first character becomes last character of the new string and so on.

"hola".reverse()  ==> "aloh"
"hola".reverse()  ==> "aloh"
takeLeft(length)

see take

"word".takeLeft(3)  ==> Answers "wor"
"word".takeLeft(0)  ==> Answers ""
"word".takeLeft(-1) ==> Throws error
"".takeLeft(2)      ==> Answers ""
"word".takeLeft(3)  ==> Answers "wor"
"word".takeLeft(0)  ==> Answers ""
"word".takeLeft(-1) ==> Throws error
"".takeLeft(2)      ==> Answers ""
takeRight(_length)

Takes last n characters of this string.

n must be zero-positive integer.

"word".takeRight(3)  ==> Answers "ord"
"word".takeRight(0)  ==> Answers ""
"word".takeRight(-1) ==> Throws error
"".takeRight(2)      ==> Answers ""
"word".takeRight(3)  ==> Answers "ord"
"word".takeRight(0)  ==> Answers ""
"word".takeRight(-1) ==> Throws error
"".takeRight(2)      ==> Answers ""
native
<(aString)

Documentation not found

<=(aString)

Documentation not found

native
>(aString)

Documentation not found

>=(aString)

Documentation not found

native
contains(element)

Documentation not found

isEmpty()

Answers whether this string has no characters

equalsIgnoreCase(aString)

Documentation not found

native
substring(index)

Documentation not found

native
substring(startIndex, endIndex)

Answers a substring of this string beginning

from an inclusive index up to another inclusive index

"walking".substring(2, 4)   ==> Answers "lk"
"walking".substring(3, 5)   ==> Answers "ki"
"walking".substring(0, 5)   ==> Answers "walki"
"walking".substring(0, 45)  ==> throws an out of range exception
"walking".substring(2, 4)   ==> Answers "lk"
"walking".substring(3, 5)   ==> Answers "ki"
"walking".substring(0, 5)   ==> Answers "walki"
"walking".substring(0, 45)  ==> throws an out of range exception
split(expression)

Splits this string around matches of the given string.

Answers a list of strings.

"this,could,be,a,list".split(",")
==> Answers ["this", "could", "be", "a", "list"]
"Esto Es una prueba".split(" ")
==> Answers ["Esto", "Es", "una", "prueba"]
"Esto Es una".split("")
==> Answers ["E","s","t","o"," ","E","s"," ","u","n","a"] , splitting into a character list
"Esto Es una".split("|")
==> Answers ["Esto Es una"], the same original string
"texto de prueba".split("texto de prueba")
==> Answers ["",""]
"a,b,,c,".split(",")
==> Answers ["a", "b", "", "c", ""]
"texto de prueba".split("de")
==> Answers ["texto ", " prueba"]
"aaaa".split("aa")
==> Answers ["", "", ""]
"this,could,be,a,list".split(",")
==> Answers ["this", "could", "be", "a", "list"]
"Esto Es una prueba".split(" ")
==> Answers ["Esto", "Es", "una", "prueba"]
"Esto Es una".split("")
==> Answers ["E","s","t","o"," ","E","s"," ","u","n","a"] , splitting into a character list
"Esto Es una".split("|")
==> Answers ["Esto Es una"], the same original string
"texto de prueba".split("texto de prueba")
==> Answers ["",""]
"a,b,,c,".split(",")
==> Answers ["a", "b", "", "c", ""]
"texto de prueba".split("de")
==> Answers ["texto ", " prueba"]
"aaaa".split("aa")
==> Answers ["", "", ""]
native
replace(expression, replacement)

Documentation not found

override native
toString()

This object (which is already a string!) is itself returned

override
printString()

String implementation of printString,

simply adds quotation marks

override native
==(other)

Documentation not found

size()

A synonym for length

take(n)

Takes first n characters of this string.

n must be zero-positive integer.

"lowercase".take(3)  ==> Answers "low"
"lowercase".take(0)  ==> Answers ""
"lowercase".take(-1) ==> Throws error
"".take(2)           ==> Answers ""
"lowercase".take(3)  ==> Answers "low"
"lowercase".take(0)  ==> Answers ""
"lowercase".take(-1) ==> Throws error
"".take(2)           ==> Answers ""
drop(n)

Documentation not found

words()

Documentation not found

capitalize()

Changes the first letter of every word to

upper case in this string.

"javier fernandes".capitalize() ==> Answers "Javier Fernandes"
"javier fernandes".capitalize() ==> Answers "Javier Fernandes"

Class Boolean

Represents a Boolean value (true or false)

noInstantiate

Comportamiento

native
and(other)

Answers the result of applying the logical AND operator

to the specified boolean operands self and other

native
&&(other)

A synonym for and operation

native
or(other)

Answers the result of applying the logical OR operator

to the specified boolean operands self and other

native
||(other)

A synonym for or operation

override native
toString()

String representation of this boolean value.

override native
==(other)

Compares this string to the specified object.

The result is true if and only if the

argument is not null and represents same value

(true or false)

native
negate()

NOT logical operation

Class Range

Represents a finite arithmetic progression

of integer numbers with optional step

If start = 1, end = 8, Range will represent [1, 2, 3, 4, 5, 6, 7, 8]

If start = 1, end = 8, step = 3, Range will represent [1, 4, 7]

since 1.3

Estado

Atributo WollokDoc
start

Documentation not found

end

Documentation not found

property step

Documentation not found

Comportamiento

override
initialize()

Instantiates a Range.

Both start and end must be integer values.

start()

Documentation not found

end()

Documentation not found

step(_step)

Documentation not found

native
forEach(closure)

Documentation not found

map(closure)

Answers a new collection that contains the result of

transforming each of self collection's elements using

a given closure.

The condition is a closure argument that takes an integer

and answers an object.

returns another list

(1..10).map({ n => n  2}) ==> Answers [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
(1..10).map({ n => n  2}) ==> Answers [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
flatMap(closure)

Documentation not found

asList()

Documentation not found

isEmpty()

Documentation not found

fold(seed, foldClosure)

Documentation not found

size()

Answers the number of elements

new Range(start = 0, end = 2).size()  ==> Answers 3
new Range(start = -2, end = 2).size() ==> Answers 5
new Range(start = 0, end = 2).size()  ==> Answers 3
new Range(start = -2, end = 2).size() ==> Answers 5
any(closure)

Documentation not found

all(closure)

Answers whether all the elements of range satisfy a given

condition. The condition is a closure argument that takes a number

and answers a boolean value.

returns true/false

(1..5).all { number => number.odd() }    => Answers false
<strong>see</strong> List#all(closure)
(1..5).all { number => number.odd() }    => Answers false
<strong>see</strong> List#all(closure)
filter(closure)

Answers a new list with the elements meeting

a given condition. The condition is a closure argument that

takes a single element and answers a boolean.

(1..4).filter({ number => number.even() })   => Answers [2, 4]
<strong>see</strong> List#filter(closure)
(1..4).filter({ number => number.even() })   => Answers [2, 4]
<strong>see</strong> List#filter(closure)
min()

Answers the element that represents the minimum value in the range.

The criteria is by direct comparison of the elements (they must be sortable).

(1..5).min()  => Answers 1
<strong>see</strong> List#min()
(1..5).min()  => Answers 1
<strong>see</strong> List#min()
max()

Answers the element that represents the maximum value in the range.

(1..15).max()                       =>  Answers 15
new Range(start = 2, end = 5).max() => Answers 5
<strong>see</strong> List#max()
(1..15).max()                       =>  Answers 15
new Range(start = 2, end = 5).max() => Answers 5
<strong>see</strong> List#max()
native
anyOne()

Answers a random integer contained in the range

new Range(start = 1, end = 3).anyOne() ==> Answers 1 or 2 or 3
new Range(start = 1, end = 3).anyOne() ==> Answers 1 or 2 or 3
contains(element)

Tests whether a number is contained in the range

new Range(start = 2, end = 5).contains(4) ==> Answers true
(new Range(start = 2, end = 5)).contains(0) ==> Answers false
new Range(start = 2, end = 5).contains(4) ==> Answers true
(new Range(start = 2, end = 5)).contains(0) ==> Answers false
sum()

Sums all elements in the collection.

returns a number

(1..5).sum()  => Answers 15
<strong>see</strong> List#sum()
(1..5).sum()  => Answers 15
<strong>see</strong> List#sum()
sum(closure)

Sums all elements that match the boolean closure

(1..9).sum({ i => if (i.even()) i else 0 }) ==> Answers 20
(1..9).sum({ i => if (i.even()) i else 0 }) ==> Answers 20
count(closure)

Counts how many elements match the boolean closure

(1..9).count({ i => i.even() }) ==> Answers 4 (2, 4, 6 and 8 are even)
(1..9).count({ i => i.even() }) ==> Answers 4 (2, 4, 6 and 8 are even)
find(closure)

Answers the number of the range that satisfies a given condition.

throws ElementNotFoundException if no element matched the given predicate

(1..5).find { number => number.even() }   ==> Answers 2
<strong>see</strong> List#find(closure)
(1..5).find { number => number.even() }   ==> Answers 2
<strong>see</strong> List#find(closure)
findOrElse(closure, continuation)

Finds the first number matching the boolean closure,

or evaluates the continuation block closure if no element is found

(1..5).findOrElse({ number => number < 0 }, { 100 })     => Answers 100
(1..5).findOrElse({ number => number.even() }, { 100 })  => Answers 2
<strong>see</strong> List#findOrElse(predicate, continuation)
(1..5).findOrElse({ number => number < 0 }, { 100 })     => Answers 100
(1..5).findOrElse({ number => number.even() }, { 100 })  => Answers 2
<strong>see</strong> List#findOrElse(predicate, continuation)
findOrDefault(predicate, value)

Answers the number of the range that satisfies a given condition,

or the given default otherwise, if no element matched the predicate.

(1..5).findOrDefault({ number => number.even() }, 0) => Answers 2
(1..5).findOrDefault({ number => number < 0 }, 0)    => Answers 0
<strong>see</strong> List#findOrDefault(predicate, value)
(1..5).findOrDefault({ number => number.even() }, 0) => Answers 2
(1..5).findOrDefault({ number => number < 0 }, 0)    => Answers 0
<strong>see</strong> List#findOrDefault(predicate, value)
sortedBy(closure)

Answers a new List that contains the elements of self collection

sorted by a criteria given by a closure. The closure receives two objects

X and Y and answers a boolean, true if X should come before Y in the

resulting collection.

returns a new List

(1..5).sortedBy { a, b => a > b } => Answers [5, 4, 3, 2, 1]
<strong>see</strong> List#sortBy
(1..5).sortedBy { a, b => a > b } => Answers [5, 4, 3, 2, 1]
<strong>see</strong> List#sortBy
override
toString()

String representation of this range object

Class Closure

Represents an executable piece of code. You can create a closure,

assign it to a reference, evaluate it many times,

send it as parameter to another object, and many useful things.

since 1.3

noInstantiate

Comportamiento

native
apply(parameters)

Evaluates this closure passing its parameters

{ number => number + 1 }.apply(8) ==> Answers 9 // 1 parameter
{ "screw" + "driver" }.apply()    ==> Answers "screwdriver" // no parameter
{ number => number + 1 }.apply(8) ==> Answers 9 // 1 parameter
{ "screw" + "driver" }.apply()    ==> Answers "screwdriver" // no parameter
override native
toString()

String representation of this closure object

Singleton calendar

Utility object to contain Date and Date-related info, such as WKO and factory methods.

since 3.0.0

Estado

Atributo WollokDoc
const property monday

Documentation not found

const property tuesday

Documentation not found

const property wednesday

Documentation not found

const property thursday

Documentation not found

const property friday

Documentation not found

const property saturday

Documentation not found

const property sunday

Documentation not found

const property daysOfWeek

Documentation not found

Comportamiento

native
today()

Documentation not found

yesterday()

Documentation not found

tomorrow()

Documentation not found

Class Date

Represents a Date (without time). A Date is immutable, once created you can not change it.

since 1.4.5

Estado

Atributo WollokDoc
const property day

Documentation not found

const property month

Documentation not found

const property year

Documentation not found

Comportamiento

override
toString()

String representation of a date

override native
==(_aDate)

Two dates are equals if they represent the same date

native
plusDays(_days)

Answers a copy of this Date with the specified number of days added.

Parameter must be an integer value.

This operation has no side effect (a new date is returned).

new Date(day = 12, month = 5, year = 2018).plusDays(1)
==> Answers 13/5/2018, a day forward
new Date(day = 12, month = 5, year = 2018).plusDays(-1)
==> Answers 11/5/2018, a day back
new Date(day = 12, month = 5, year = 2018).plusDays(1)
==> Answers 13/5/2018, a day forward
new Date(day = 12, month = 5, year = 2018).plusDays(-1)
==> Answers 11/5/2018, a day back
native
plusMonths(_months)

Answers a copy of this Date with the specified number of months added.

Parameter must be an integer value.

This operation has no side effect (a new date is returned).

new Date(day = 31, month = 1, year = 2018).plusMonths(1)
==> Answers 28/2/2018, a month forward
new Date(day = 12, month = 5, year = 2018).plusMonths(-1)
==> Answers 12/4/2018, a month back
new Date(day = 31, month = 1, year = 2018).plusMonths(1)
==> Answers 28/2/2018, a month forward
new Date(day = 12, month = 5, year = 2018).plusMonths(-1)
==> Answers 12/4/2018, a month back
native
plusYears(_years)

Answers a copy of this Date with the specified number of years added.

Parameter must be an integer value.

This operation has no side effect (a new date is returned).

new Date(day = 31, month = 1, year = 2018).plusYears(1)
==> Answers 31/1/2019, a year forward
new Date(day = 12, month = 5, year = 2018).plusYears(-1)
==> Answers 12/5/2017, a year back
new Date(day = 31, month = 1, year = 2018).plusYears(1)
==> Answers 31/1/2019, a year forward
new Date(day = 12, month = 5, year = 2018).plusYears(-1)
==> Answers 12/5/2017, a year back
native
isLeapYear()

Checks if the year is a leap year, like 2000, 2004, 2008...

new Date(day = 12, month = 5, year = 2018).isLeapYear() ==> Answers false
new Date(day = 12, month = 5, year = 2018).isLeapYear() ==> Answers false
dayOfWeek()

Answers the day of the week of the Date with an object representation.

There is a wko (well known object) for every day of the week.

new Date(day = 24, month = 2, year = 2018).dayOfWeek() ==> Answers saturday object
new Date(day = 24, month = 2, year = 2018).dayOfWeek() ==> Answers saturday object
native
internalDayOfWeek()

Answers the day of week of the Date, where

1 = MONDAY

2 = TUESDAY

3 = WEDNESDAY

...

7 = SUNDAY

new Date(day = 24, month = 2, year = 2018).internalDayOfWeek() ==> Answers 6 (SATURDAY)
new Date(day = 24, month = 2, year = 2018).internalDayOfWeek() ==> Answers 6 (SATURDAY)
native
-(_aDate)

Answers the difference in days between two dates, assuming self is minuend and _aDate is subtrahend.

new Date().plusDays(4) - new Date() ==> Answers 4
new Date() - new Date().plusDays(2) ==> Answers -2
new Date().plusDays(4) - new Date() ==> Answers 4
new Date() - new Date().plusDays(2) ==> Answers -2
native
minusDays(_days)

Answers a copy of this date with the specified number of days subtracted.

This instance is immutable and unaffected by this method call.

Parameter must be an integer value.

This operation has no side effect (a new date is returned).

new Date(day = 1, month = 1, year = 2009).minusDays(1)
==> Answers 31/12/2008, a day back
new Date(day = 1, month = 1, year = 2009).minusDays(-1)
==> Answers 2/1/2009, a day forward
new Date(day = 1, month = 1, year = 2009).minusDays(1)
==> Answers 31/12/2008, a day back
new Date(day = 1, month = 1, year = 2009).minusDays(-1)
==> Answers 2/1/2009, a day forward
native
minusMonths(_months)

Answers a copy of this date with the specified number of months subtracted.

Parameter must be an integer value.

This operation has no side effect (a new date is returned).

new Date(day = 1, month = 1, year = 2009).minusMonths(1)
==> Answers 1/12/2008, a month back
new Date(day = 1, month = 1, year = 2009).minusMonths(-1)
==> Answers 1/2/2009, a month forward
new Date(day = 1, month = 1, year = 2009).minusMonths(1)
==> Answers 1/12/2008, a month back
new Date(day = 1, month = 1, year = 2009).minusMonths(-1)
==> Answers 1/2/2009, a month forward
native
minusYears(_years)

Answers a copy of this date with the specified number of years subtracted.

Parameter must be an integer value.

This operation has no side effect (a new date is returned).

new Date(day = 1, month = 1, year = 2009).minusYears(1)
==> Answers 1/1/2008, a year back
new Date(day = 1, month = 1, year = 2009).minusYears(-1)
==> Answers 1/1/2010, a year forward
new Date(day = 1, month = 1, year = 2009).minusYears(1)
==> Answers 1/1/2008, a year back
new Date(day = 1, month = 1, year = 2009).minusYears(-1)
==> Answers 1/1/2010, a year forward
native
<(_aDate)

Documentation not found

native
>(_aDate)

Documentation not found

<=(_aDate)

Documentation not found

>=(_aDate)

Documentation not found

between(_startDate, _endDate)

Documentation not found

override native
shortDescription()

Documentation not found

isWorkDay()

Answer whether the day is a work day (between monday and friday)

new Date(day = 13, month = 7, year = 2020).isWorkDay()
==> Answers true
new Date(day = 13, month = 7, year = 2020).isWorkDay()
==> Answers true
isWeekendDay()

Documentation not found

Singleton io

Represents an Input/Output event handler.

since 1.9.2

Estado

Atributo WollokDoc
const property eventHandlers

// TODO: merge handlers

const property timeHandlers

Documentation not found

const property collitionHandlers

Documentation not found

property eventQueue

Documentation not found

property currentTime

Documentation not found

property exceptionHandler

Documentation not found

property domainExceptionHandler

Documentation not found

Comportamiento

queueEvent(event)

Documentation not found

eventHandlersFor(event)

Documentation not found

addEventHandler(event, callback)

Documentation not found

removeEventHandler(event)

Documentation not found

timeHandlers(name)

Documentation not found

containsTimeEvent(name)

Documentation not found

addTimeHandler(name, callback)

Documentation not found

removeTimeHandler(name)

Documentation not found

collitionHandlersFor(event)

Documentation not found

addCollitionHandler(event, callback)

Documentation not found

removeCollitionHandler(event)

Documentation not found

clear()

Documentation not found

flushEvents(time)

Documentation not found

runHandler(callback)

Documentation not found



lib.wlk

Singleton console

Console is a global wollok object that implements a character-based console device

called "standard input/output" stream

Comportamiento

native
println(obj)

Prints a String with end-of-line character

native
readLine()

Reads a line from input stream

native
readInt()

Reads an int character from input stream

native
newline()

Returns the system's representation of a new line:

- \n in Unix systems

- \r\n in Windows systems

Class OtherValueExpectedException

Exception to handle other values expected in assert.throwsException... methods

Class AssertionException

Exception to handle difference between current and expected values

in assert.throwsException... methods

Estado

Atributo WollokDoc
const property expected

Documentation not found

const property actual

Documentation not found

Singleton assert

Assert object simplifies testing conditions

Comportamiento

that(value)

Tests whether value is true. Otherwise throws an exception.

assert.that(7.even())   ==> throws an exception "Value was not true"
assert.that(8.even())   ==> ok, nothing happens
assert.that(7.even())   ==> throws an exception "Value was not true"
assert.that(8.even())   ==> ok, nothing happens
notThat(value)

Documentation not found

equals(expected, actual)

Documentation not found

notEquals(expected, actual)

Documentation not found

doesNotThrowException(block)

Documentation not found

throwsException(block)

Documentation not found

throwsExceptionLike(exceptionExpected, block)

Documentation not found

throwsExceptionWithMessage(errorMessage, block)

Documentation not found

throwsExceptionWithType(exceptionExpected, block)

Documentation not found

throwsExceptionByComparing(block, comparison)

Documentation not found

fail(message)

Documentation not found

override
equals(value)

Documentation not found

Class StringPrinter

Documentation not found

Estado

Atributo WollokDoc
buffer

Documentation not found

Comportamiento

println(obj)

Documentation not found

getBuffer()

Documentation not found



game.wlk

Singleton game

Documentation not found

Estado

Atributo WollokDoc
const visuals

Collection of visual objects in the game

property running

Documentation not found

property errorReporter

Allows to configure a visual component as "error reporter".

Then every error in game board will be reported by this visual component,

in a balloon message form.

Comportamiento

override
initialize()

Documentation not found

native
addVisual(positionable)

Documentation not found

addVisualCharacter(visual)

Adds an object to the board for drawing it. It can be moved with arrow keys.

That object should understand a position property

(implemented by a reference or getter method).

game.addVisualCharacter(pepita) ==> pepita should have a position property
game.addVisualCharacter(pepita) ==> pepita should have a position property
native
removeVisual(visual)

Documentation not found

native
hasVisual(visual)

Verifies if an object is currently in the board.

game.hasVisual(pepita)
game.hasVisual(pepita)
native
allVisuals()

Returns all visual objects added to the board.

game.allVisuals()
game.allVisuals()
whenKeyPressedDo(event, action)

Adds a block that will be executed each time a specific key is pressed

see keyboard.onPressDo()

whenCollideDo(visual, action)

Documentation not found

onCollideDo(visual, action)

Documentation not found

onTick(milliseconds, name, action)

Documentation not found

schedule(milliseconds, action)

Documentation not found

removeTickEvent(event)

Documentation not found

onSameCell(position1, position2)

Documentation not found

native
getObjectsIn(position)

Returns all objects in given position.

game.getObjectsIn(game.origin())
game.getObjectsIn(game.origin())
native
say(visual, message)

Draws a dialog balloon with given message in given visual object position.

game.say(pepita, "hola!")
game.say(pepita, "hola!")
clear()

Removes all visual objects in game and configurations (colliders, keys, etc).

native
colliders(visual)

Documentation not found

currentTime()

Returns the current Tick.

flushEvents(time)

Runs all time event for the given time.

uniqueCollider(visual)

Documentation not found

stop()

Stops render the board and finish the game.

start()

Documentation not found

at(x, y)

Documentation not found

origin()

Documentation not found

center()

Returns the center board position (rounded down).

native
title(title)

Sets game title.

native
title()

Returns game title.

native
width(width)

Sets board width (in cells).

native
width()

Returns board width (in cells).

native
height(height)

Sets board height (in cells).

native
height()

Returns board height (in cells).

native
ground(image)

Sets cells background image.

cellSize(size)

Sets cells size.

native
doCellSize(size)

Documentation not found

native
boardGround(image)

Sets full background image.

native
hideAttributes(visual)

Attributes will not show when user mouse over a visual component.

Default behavior is to show them.

native
showAttributes(visual)

Attributes will appear again when user mouse over a visual component.

Default behavior is to show them, so this is not necessary.

sound(audioFile)

Returns a sound object. Audio file must be a .mp3, .ogg or .wav file.

tick(interval, action, execInmediately)

Documentation not found

Class AbstractPosition

Documentation not found

Comportamiento

abstract
x()

Documentation not found

abstract
y()

Documentation not found

abstract
createPosition(x, y)

Documentation not found

right(n)

Documentation not found

left(n)

Returns a new Position n steps left from this one.

up(n)

Returns a new Position n steps up from this one.

down(n)

Returns a new Position, n steps down from this one.

say(element, message)

Draw a dialog balloon with given message in given visual object position.

allElements()

Documentation not found

clone()

//TODO: Implement native

distance(position)

Returns the distance between given position and self.

clear()

Documentation not found

override
==(other)

Documentation not found

override
toString()

String representation of a position

round()

Returns a new position with its coordinates rounded

Class Position

Represents a position in a two-dimensional gameboard.

It is an immutable object since Wollok 1.8.0

Estado

Atributo WollokDoc
const x

Documentation not found

const y

Documentation not found

Comportamiento

override
x()

Documentation not found

override
y()

Documentation not found

override
createPosition(_x, _y)

Documentation not found

Class MutablePosition

Documentation not found

Estado

Atributo WollokDoc
x

Documentation not found

y

Documentation not found

Comportamiento

override
x()

Documentation not found

override
y()

Documentation not found

override
createPosition(_x, _y)

Documentation not found

goRight(n)

Documentation not found

goLeft(n)

Documentation not found

goUp(n)

Documentation not found

goDown(n)

Documentation not found

Singleton keyboard

Keyboard object handles all keys movements. There is a method for each key.

keyboard.i().onPressDo { game.say(pepita, "hola!") }
=> when user hits "i" key, pepita will say "hola!"
keyboard.any().onPressDo { game.say(pepita, "you pressed a key!") }
=> any key pressed will activate its closure
keyboard.i().onPressDo { game.say(pepita, "hola!") }
=> when user hits "i" key, pepita will say "hola!"
keyboard.any().onPressDo { game.say(pepita, "you pressed a key!") }
=> any key pressed will activate its closure

Comportamiento

any()

Documentation not found

num(n)

Documentation not found

letter(l)

Documentation not found

arrow(a)

Documentation not found

num0()

Documentation not found

num1()

Documentation not found

num2()

Documentation not found

num3()

Documentation not found

num4()

Documentation not found

num5()

Documentation not found

num6()

Documentation not found

num7()

Documentation not found

num8()

Documentation not found

num9()

Documentation not found

a()

Documentation not found

b()

Documentation not found

c()

Documentation not found

d()

Documentation not found

e()

Documentation not found

f()

Documentation not found

g()

Documentation not found

h()

Documentation not found

i()

Documentation not found

j()

Documentation not found

k()

Documentation not found

l()

Documentation not found

m()

Documentation not found

n()

Documentation not found

o()

Documentation not found

p()

Documentation not found

q()

Documentation not found

r()

Documentation not found

s()

Documentation not found

t()

Documentation not found

u()

Documentation not found

v()

Documentation not found

w()

Documentation not found

x()

Documentation not found

y()

Documentation not found

z()

Documentation not found

alt()

Documentation not found

backspace()

Documentation not found

control()

Documentation not found

del()

Documentation not found

center()

Documentation not found

down()

Documentation not found

left()

Documentation not found

right()

Documentation not found

up()

Documentation not found

enter()

Documentation not found

minusKey()

Documentation not found

plusKey()

Documentation not found

shift()

Documentation not found

slash()

Documentation not found

space()

Documentation not found

Class Key

Documentation not found

Estado

Atributo WollokDoc
const property keyCodes

Documentation not found

Comportamiento

onPressDo(action)

Documentation not found

Class Sound

Wollok Game Sound object

Estado

Atributo WollokDoc
const property file

Documentation not found

Comportamiento

override
initialize()

Documentation not found

native
play()

Documentation not found

native
played()

Answers whether the sound has been played or not.

native
stop()

Stops playing the sound and disposes resources.

native
pause()

Pauses the sound.

Throws error if the sound is already paused or if the sound hasn't been played yet.

native
resume()

Resumes playing the sound.

Throws error if the sound is not paused.

native
paused()

Answers whether the sound is paused or not.

native
volume(newVolume)

Changes absolute volume, values must be between 0 and 1.

mySound.volume(0)  => The sound is now muted.
mySound.volume(0.5)  => New volume is half of the original sound's volume
mySound.volume(mySound.volume()0.5) => New volume is half of the current volume
mySound.volume(0)  => The sound is now muted.
mySound.volume(0.5)  => New volume is half of the original sound's volume
mySound.volume(mySound.volume()0.5) => New volume is half of the current volume
native
volume()

Answers the volume of the sound.

native
shouldLoop(looping)

Sets whether the sound should loop or not.

native
shouldLoop()

Answers whether the sound is set to loop or not.

Class Tick

Documentation not found

Estado

Atributo WollokDoc
interval

Milliseconds to wait between each action

const name

Documentation not found

const action

Block to execute after each interval time lapse

const inmediate

Documentation not found

Comportamiento

start()

Starts looping the action passed in to the tick

object when it was instantiated.

stop()

Documentation not found

reset()

Documentation not found

interval(milliseconds)

Documentation not found

isRunning()

Documentation not found



mirror.wlk

Class InstanceVariableMirror

Documentation not found

Estado

Atributo WollokDoc
const target

Documentation not found

const property name

Documentation not found

Comportamiento

value()

Documentation not found

valueToString()

Documentation not found

override
toString()

Documentation not found

Class ObjectMirror

Represents an object capable of give information of another object.

It offers a reflection mechanism that is completely decoupled

from the object whose structure is being introspected.

Estado

Atributo WollokDoc
const property target

Documentation not found

Comportamiento

native
resolve(attributeName)

Documentation not found

native
instanceVariableFor(name)

Retrieves a specific variable for target object. Expects a name

native
instanceVariables()

Answers a list of instance variables for target object



vm.wlk

Singleton runtime

Object for Wollok implementation for runtime decisions

Comportamiento

native
isInteractive()

true if running REPL, false otherwise