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 |
Comportamiento
initialize()
Exception.initialize()
printStackTrace()
Exception.printStackTrace()
Prints this exception and its backtrace to the console
getStackTraceAsString()
Exception.getStackTraceAsString()
Prints this exception and its backtrace as a string value
printStackTrace(printer)
Exception.printStackTrace(printer)
private
Prints this exception and its backtrace to the specified printer
printStackTraceWithPrefix(prefix, printer)
Exception.printStackTraceWithPrefix(prefix, printer)
private
createStackTraceElement(contextDescription, location)
Exception.createStackTraceElement(contextDescription, location)
private
getFullStackTrace()
Exception.getFullStackTrace()
Provides programmatic access to the stack trace information
printed by printStackTrace() with full path files for linking
getStackTrace()
Exception.getStackTrace()
Provides programmatic access to the stack trace information
printed by printStackTrace().
==(other)
Exception.==(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 |
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 | |
const property location |
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()
Object.initialize()
identity()
Object.identity()
Answers object identity of a Wollok object, represented by
a unique number in Wollok environment
kindName()
Object.kindName()
Object description in english/spanish/... (depending on i18n configuration)
className()
Object.className()
Full name of Wollok object class
private
==(other)
Object.==(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)
Object.!=(other)
Tells whether self object is not equal to the given one
===(other)
Object.===(other)
Tells whether self object is identical (the same) to the given one.
It does it by comparing their identities.
So self basically relies on the wollok.lang.Integer equality (which is native)
!==(other)
Object.!==(other)
Tells whether self object is not identical (the same) to the given one.
See === message.
equals(other)
Object.equals(other)
o1.equals(o2) is a synonym for o1 == o2
->(other)
Object.->(other)
Generates a Pair key-value association. see Pair.
toString()
Object.toString()
String representation of Wollok object
shortDescription()
Object.shortDescription()
Shows a short, internal representation
printString()
Object.printString()
Provides a visual representation of Wollok Object
By default, same as toString but can be overridden
like in String
messageNotUnderstood(messageName, parameters)
Object.messageNotUnderstood(messageName, parameters)
private
generateDoesNotUnderstandMessage(target, messageName, parametersSize)
Object.generateDoesNotUnderstandMessage(target, messageName, parametersSize)
private
internal method: generates a does not understand message
parametersSize must be an integer value
error(aMessage)
Object.error(aMessage)
Builds an exception with a message
checkNotNull(value, message)
Object.checkNotNull(value, message)
private
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 | |
const property y |
Comportamiento
key()
Pair.key()
value()
Pair.value()
==(other)
Pair.==(other)
Two pairs are equal if they have the same values
toString()
Pair.toString()
String representation of a Pair
Class Collection
The root class in the collection hierarchy.
A collection represents a group of objects, known as its elements.
Comportamiento
max(closure)
Collection.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.
max()
Collection.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.
maxIfEmpty(toComparableClosure, emptyCaseClosure)
Collection.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.
maxIfEmpty(emptyCaseClosure)
Collection.maxIfEmpty(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 by direct comparison of the elements.
The closure to execute when the collection is empty is given as a second
argument.
min(closure)
Collection.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).
min()
Collection.min()
Answers the element that represents the minimum value in the
non-empty collection.
The criteria is by direct comparison of the elements.
minIfEmpty(toComparableClosure, emptyCaseClosure)
Collection.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.
minIfEmpty(emptyCaseClosure)
Collection.minIfEmpty(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 by direct comparison of the elements.
The closure to execute when the collection is empty is given as a second
argument.
absolute(closure, criteria, emptyCaseClosure)
Collection.absolute(closure, criteria, emptyCaseClosure)
private
uniqueElement()
Collection.uniqueElement()
Answers the unique element in the collection.
If collection is empty, an error is thrown.
If collection has more than one element, an error is thrown.
+(elements)
Collection.+(elements)
Concatenates this collection to all elements from the given
collection parameter giving a new collection
(no side effect)
addAll(elements)
Collection.addAll(elements)
Adds all elements from the given collection parameter to self collection.
This is a side effect operation.
removeAll(elements)
Collection.removeAll(elements)
Removes all elements of the given collection parameter from self collection.
This is a side effect operation.
removeAllSuchThat(closure)
Collection.removeAllSuchThat(closure)
Removes those elements that meet a given condition.
This is a side effect operation.
Supports empty collections.
isEmpty()
Collection.isEmpty()
Tells whether self collection has no elements
validateNotEmpty(operation)
Collection.validateNotEmpty(operation)
private
Throws error if self collection is empty
forEach(closure)
Collection.forEach(closure)
Performs an operation on every element of self collection.
The logic to execute is passed as a closure that takes a single parameter.
Supports empty collections.
returns nothing
all(predicate)
Collection.all(predicate)
Answers whether all the elements of self collection satisfy a given
condition. The condition is a closure argument that takes a single
element and answers a boolean value.
returns true/false
any(predicate)
Collection.any(predicate)
Tells whether at least one element of self collection satisfies a
given condition. The condition is a closure argument that takes a
single element and answers a boolean value.
returns true/false
find(predicate)
Collection.find(predicate)
Answers the element of self collection that satisfies a given condition.
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
throws ElementNotFoundException if no element matched the given predicate
findOrDefault(predicate, value)
Collection.findOrDefault(predicate, value)
Answers the element of self collection that satisfies a given condition,
or the given default otherwise, if no element matched the predicate.
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 default value
findOrElse(predicate, continuation)
Collection.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
count(predicate)
Collection.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
occurrencesOf(element)
Collection.occurrencesOf(element)
Counts the occurrences of a given element in self collection.
returns an integer number
sum(closure)
Collection.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
sum()
Collection.sum()
Sums all elements in the collection.
returns a number
average(closure)
Collection.average(closure)
Calculates the average of the transformation of each element into a numerical value
This is similar to call a map {} to transform each element into a
number and calculates the average value of the resulting list.
The condition is a closure argument that takes a single element and
returns a number
returns a number
average()
Collection.average()
Calculates the average of all elements in the collection.
returns a number
map(closure)
Collection.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
flatMap(closure)
Collection.flatMap(closure)
Flattens a collection of collections: Map + flatten operation
see map
see flatten
filter(closure)
Collection.filter(closure)
Answers a new collection that contains the elements that
meet a given condition. The condition is a closure argument that
takes a single element and answers a boolean.
returns another collection (same type as self one)
contains(element)
Collection.contains(element)
Answers whether this collection contains the specified element.
flatten()
Collection.flatten()
Flattens a collection of collections
toString()
Collection.toString()
private
toStringPrefix()
Collection.toStringPrefix()
private
toStringSuffix()
Collection.toStringSuffix()
private
printString()
Collection.printString()
Provides a (short) visual representation of this collection.
asList()
Collection.asList()
Converts a collection to a list
asSet()
Collection.asSet()
Converts a collection to a set (removing duplicates if necessary)
copy()
Collection.copy()
Answers a new collection of the same type and with the same content
as self. Supports empty collections.
returns a new collection
copyWithout(elementToRemove)
Collection.copyWithout(elementToRemove)
Answers a new collection without element that is passed by parameter.
If the element occurs more than once in the collection, all occurrences
will be removed.
returns a new Collection
copyWith(elementToAdd)
Collection.copyWith(elementToAdd)
Answers a new collection with the added element which is received by parameter.
returns a new Collection
sortedBy(closure)
Collection.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. Supports empty collections.
returns a new List
newInstance()
Collection.newInstance()
Answers a new, empty collection of the same type as self.
returns a new collection
anyOne()
Collection.anyOne()
see subclasses implementations
add(element)
Collection.add(element)
see subclasses implementations
remove(element)
Collection.remove(element)
see subclasses implementations
fold(element, closure)
Collection.fold(element, closure)
see subclasses implementations
size()
Collection.size()
see subclasses implementations
clear()
Collection.clear()
Removes all of the elements from this set. This is a side effect operation.
see subclasses implementations
join(separator)
Collection.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 ",")
join()
Collection.join()
Answers the concatenated string representation of the elements in the given set
with default element separator (",")
Singleton collection
Builder object for collections.
It compensates for the lack of vararg constructors.
Comportamiento
list(elements)
collection.list(elements)
set(elements)
collection.set(elements)
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
newInstance()
Set.newInstance()
private
toStringPrefix()
Set.toStringPrefix()
private
toStringSuffix()
Set.toStringSuffix()
private
asList()
Set.asList()
Converts this set to a list.
asSet()
Set.asSet()
Converts a collection to a set (removing duplicates if necessary)
anyOne()
Set.anyOne()
Answers any element of a non-empty collection
union(another)
Set.union(another)
Answers a new Set with the elements of both self and another collection.
intersection(another)
Set.intersection(another)
Answers a new Set with the elements of self that exist in another collection
difference(another)
Set.difference(another)
Answers a new Set with the elements of self that don't exist in another collection
fold(initialValue, closure)
Set.fold(initialValue, closure)
Reduce a collection to a certain value, beginning with a seed or initial value.
filter(closure)
Set.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.
max()
Set.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.
findOrElse(predicate, continuation)
Set.findOrElse(predicate, continuation)
Tries to find an element in a collection (based on a closure) or
applies a continuation closure.
add(element)
Set.add(element)
Adds the specified element to this set if it is not already present.
unsafeAdd(element)
Set.unsafeAdd(element)
private
remove(element)
Set.remove(element)
Removes the specified element from this set if it is present.
size()
Set.size()
Answers the number of elements in this set (its cardinality).
clear()
Set.clear()
Removes all of the elements from this set. This is a side effect operation.
join(separator)
Set.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 ",")
join()
Set.join()
Answers the concatenated string representation of the elements in the given set
with default element separator (",")
contains(other)
Set.contains(other)
Answers whether this collection contains the specified element.
==(other)
Set.==(other)
Two sets are equals if they have the same elements, no matter
the order.
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
get(index)
List.get(index)
Answers the element at the specified position in this non-empty list.
The first char value of the sequence is at index 0,
the next at index 1, and so on, as for array indexing.
Index must be a positive and integer value.
newInstance()
List.newInstance()
Creates a new list
anyOne()
List.anyOne()
Answers any element of a non-empty collection.
first()
List.first()
Answers first element of the non-empty list
returns first element
head()
List.head()
Synonym for first method
last()
List.last()
Answers the last element of the non-empty list.
returns last element
toStringPrefix()
List.toStringPrefix()
private
toStringSuffix()
List.toStringSuffix()
private
asList()
List.asList()
Converts this collection to a list. No effect on Lists.
see List
asSet()
List.asSet()
Converts a collection to a set (removing duplicates if necessary)
subList(start)
List.subList(start)
Answers a view of the portion of this list between the specified start index
and the end of the list. Remember first element is position 0,
second is position 1, and so on.
If toIndex exceeds length of list, no error is thrown.
subList(start, end)
List.subList(start, end)
Answers a view of the portion of this list between the specified fromIndex
and toIndex, both inclusive. Remember first element is position 0,
second is position 1, and so on.
If toIndex exceeds length of list, no error is thrown.
sortBy(closure)
List.sortBy(closure)
Sorts elements of a list by a specific closure.
Order of elements is modified (produces effect).
take(n)
List.take(n)
Takes first n elements of a list.
drop(n)
List.drop(n)
Answers a new list dropping first n elements of a list.
This operation has no side effect.
reverse()
List.reverse()
Answers a new list reversing the elements,
so that first element becomes last element of the new list and so on.
This operation has no side effect.
filter(closure)
List.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.
contains(obj)
List.contains(obj)
Answers whether this collection contains the specified element.
max()
List.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.
fold(initialValue, closure)
List.fold(initialValue, closure)
Reduce a collection to a certain value, beginning with a seed or initial value
findOrElse(predicate, continuation)
List.findOrElse(predicate, continuation)
Finds the first element matching the boolean closure,
or evaluates the continuation block closure if no element is found
add(element)
List.add(element)
Adds the specified element as last one
remove(element)
List.remove(element)
Removes an element in this list, if it is present.
size()
List.size()
Answers the number of elements
clear()
List.clear()
Removes all of the mappings from this Dictionary.
This is a side effect operation.
join(separator)
List.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 ",")
join()
List.join()
Answers the concatenated string representation of the elements in the given set,
using default element separator (",")
==(other)
List.==(other)
A list is == another list if all elements are equal (defined by == message)
withoutDuplicates()
List.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()
List.randomize()
Shuffles the order of the elements in the list.
This is a side effect operation.
randomized()
List.randomized()
Answers a new list of the same type and with the same content in a random order
Class Dictionary
Represents a set of key -> values
Comportamiento
initialize()
Dictionary.initialize()
put(_key, _value)
Dictionary.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.
basicGet(_key)
Dictionary.basicGet(_key)
Answers the value to which the specified key is mapped,
or null if this Dictionary contains no mapping for the key.
getOrElse(_key, _closure)
Dictionary.getOrElse(_key, _closure)
Answers the value to which the specified key is mapped,
or evaluates a non-parameter closure otherwise.
get(_key)
Dictionary.get(_key)
Answers the value to which the specified key is mapped.
If this Dictionary contains no mapping for the key, an error is thrown.
size()
Dictionary.size()
Answers the number of key-value mappings in this Dictionary.
isEmpty()
Dictionary.isEmpty()
Answers whether the dictionary has no elements
containsKey(_key)
Dictionary.containsKey(_key)
Answers whether this Dictionary contains a mapping for the specified key.
containsValue(_value)
Dictionary.containsValue(_value)
Answers whether if this Dictionary maps one or more keys to the specified value.
remove(_key)
Dictionary.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.
keys()
Dictionary.keys()
Answers a list of the keys contained in this Dictionary.
values()
Dictionary.values()
Answers a list of the values contained in this Dictionary.
forEach(closure)
Dictionary.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.
clear()
Dictionary.clear()
Removes all of the mappings from this Dictionary.
This is a side effect operation.
toString()
Dictionary.toString()
String representation of a Dictionary
==(other)
Dictionary.==(other)
Two dictionaries are equal if they have the same keys and values
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
coerceToInteger()
Number.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)
coerceToPositiveInteger()
Number.coerceToPositiveInteger()
private
see coerceToInteger
Applies coercing strategy to integer. And throws exception if it is negative.
===(other)
Number.===(other)
Two references are identical if they are the same number
+(other)
Number.+(other)
-(other)
Number.-(other)
*(other)
Number.*(other)
/(other)
Number./(other)
div(other)
Number.div(other)
Integer division between self and other
**(other)
Number.**(other)
raisedTo operation
%(other)
Number.%(other)
Answers remainder of division between self and other
toString()
Number.toString()
String representation of self number
..(end)
Number...(end)
Builds a Range between self and end
>(other)
Number.>(other)
<(other)
Number.<(other)
>=(other)
Number.>=(other)
<=(other)
Number.<=(other)
abs()
Number.abs()
Answers absolute value of self
invert()
Number.invert()
Inverts sign of self
max(other)
Number.max(other)
Answers the greater number between two
min(other)
Number.min(other)
Answers the lower number between two. see max
limitBetween(limitA, limitB)
Number.limitBetween(limitA, limitB)
Given self and a range of integer values,
answers self if it is in that range
or nearest value from self to that range
between(min, max)
Number.between(min, max)
Answers whether self is between min and max
squareRoot()
Number.squareRoot()
Answers squareRoot of self
square()
Number.square()
Answers square of self
even()
Number.even()
Answers whether self is an even number
(divisible by 2, mathematically 2k).
Self must be an integer value
odd()
Number.odd()
Answers whether self is an odd number
(not divisible by 2, mathematically 2k + 1).
Self must be an integer value
rem(other)
Number.rem(other)
Answers remainder between self and other
stringValue()
Number.stringValue()
Self as String value. Equivalent: toString()
roundUp(_decimals)
Number.roundUp(_decimals)
Rounds up self up to a certain amount of decimals.
Amount of decimals must be a positive and integer value.
truncate(_decimals)
Number.truncate(_decimals)
Truncates self up to a certain amount of decimals.
Amount of decimals must be a positive and integer value.
randomUpTo(max)
Number.randomUpTo(max)
Answers a random number between self and max
roundUp()
Number.roundUp()
Answers the next integer greater than self
round()
Number.round()
Returns the value of a number rounded to the nearest integer.
floor()
Number.floor()
Converts a decimal number into an integer truncating the decimal part.
gcd(other)
Number.gcd(other)
greater common divisor.
Both self and "other" parameter are coerced to be integer values.
lcm(other)
Number.lcm(other)
least common multiple.
Both self and "other" parameter are coerced to be integer values.
digits()
Number.digits()
Number of digits of self (without sign)
isInteger()
Number.isInteger()
Tells if this number can be considered an integer number.
isPrime()
Number.isPrime()
Answers whether self is a prime number,
like 2, 3, 5, 7, 11 ...
Self must be an integer positive value
times(action)
Number.times(action)
Executes the given action n times (n = self)
Self must be a positive integer value.
The closure must have one argument (index goes from 1 to self)
plus()
Number.plus()
Allows users to define a positive number with 1 or +1
Class String
Strings are constant;
their values cannot be changed after they are created.
noInstantiate
Comportamiento
length()
String.length()
Answers the number of elements
charAt(index)
String.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)
String.+(other)
Concatenates the specified string to the end of this string.
concat(other)
String.concat(other)
Concatenates the specified string to the end of this string. Same as +.
startsWith(prefix)
String.startsWith(prefix)
Tests if this string starts with the specified prefix.
It is case sensitive.
endsWith(suffix)
String.endsWith(suffix)
Tests if this string ends with the specified suffix.
It is case sensitive.
see startsWith
indexOf(other)
String.indexOf(other)
Answers the index within this string of the first occurrence
of the specified character.
If character is not present, Answers -1
lastIndexOf(other)
String.lastIndexOf(other)
Answers the index within this string of the last
occurrence of the specified character.
If character is not present, Answers -1
toLowerCase()
String.toLowerCase()
Converts all of the characters in this String to lower case
toUpperCase()
String.toUpperCase()
Converts all of the characters in this String to upper case
trim()
String.trim()
Answers a string whose value is this string,
with any leading and trailing whitespace removed.
reverse()
String.reverse()
Answers a string reversing this string,
so that first character becomes last character of the new string and so on.
takeLeft(length)
String.takeLeft(length)
see take
takeRight(_length)
String.takeRight(_length)
Takes last n characters of this string.
n must be zero-positive integer.
<(aString)
String.<(aString)
<=(aString)
String.<=(aString)
>(aString)
String.>(aString)
>=(aString)
String.>=(aString)
contains(element)
String.contains(element)
Answers whether this string contains the specified sequence of char values.
It is a case sensitive test.
isEmpty()
String.isEmpty()
Answers whether this string has no characters
equalsIgnoreCase(aString)
String.equalsIgnoreCase(aString)
Compares this String to another String, ignoring case considerations.
substring(index)
String.substring(index)
Answers a substring of this string beginning from
an inclusive index. Parameter index must be a positive
integer value.
substring(startIndex, endIndex)
String.substring(startIndex, endIndex)
Answers a substring of this string beginning
from an inclusive index up to another inclusive index
split(expression)
String.split(expression)
Splits this string around matches of the given string.
Answers a list of strings.
replace(expression, replacement)
String.replace(expression, replacement)
Answers a string resulting from replacing all occurrences of
expression in this string with replacement
toString()
String.toString()
This object (which is already a string!) is itself returned
printString()
String.printString()
String implementation of printString,
simply adds quotation marks
==(other)
String.==(other)
Compares this string to the specified object.
The result is true if and only if the
argument is not null and is a String object
that represents the same sequence of characters as this object.
size()
String.size()
A synonym for length
take(n)
String.take(n)
Takes first n characters of this string.
n must be zero-positive integer.
drop(n)
String.drop(n)
Answers a new string dropping
first n characters of this string.
n must be zero-positive integer.
words()
String.words()
Splits this strings into several words.
capitalize()
String.capitalize()
Changes the first letter of every word to
upper case in this string.
Class Boolean
Represents a Boolean value (true or false)
noInstantiate
Comportamiento
and(other)
Boolean.and(other)
Answers the result of applying the logical AND operator
to the specified boolean operands self and other
&&(other)
Boolean.&&(other)
A synonym for and operation
or(other)
Boolean.or(other)
Answers the result of applying the logical OR operator
to the specified boolean operands self and other
||(other)
Boolean.||(other)
A synonym for or operation
toString()
Boolean.toString()
String representation of this boolean value.
==(other)
Boolean.==(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)
negate()
Boolean.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 | |
end | |
property step |
Comportamiento
initialize()
Range.initialize()
start()
Range.start()
Getter for start attribute
end()
Range.end()
Getter for end attribute
step(_step)
Range.step(_step)
Setter for step attribute.
forEach(closure)
Range.forEach(closure)
Iterates over a Range from start to end, based on step.
map(closure)
Range.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
flatMap(closure)
Range.flatMap(closure)
Map + flatten operation
see map
see flatten
asList()
Range.asList()
private
isEmpty()
Range.isEmpty()
Answers whether this range contains no elements
see Collection#isEmpty()
fold(seed, foldClosure)
Range.fold(seed, foldClosure)
Reduce a range to a certain value, beginning with a seed or initial value.
size()
Range.size()
Answers the number of elements
any(closure)
Range.any(closure)
Tells whether at least one element of range satisfies a
given condition. The condition is a closure argument that takes a
number and answers a boolean value.
returns true/false
all(closure)
Range.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
filter(closure)
Range.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.
min()
Range.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).
max()
Range.max()
Answers the element that represents the maximum value in the range.
anyOne()
Range.anyOne()
Answers a random integer contained in the range
contains(element)
Range.contains(element)
Tests whether a number is contained in the range
sum()
Range.sum()
Sums all elements in the collection.
returns a number
sum(closure)
Range.sum(closure)
Sums all elements that match the boolean closure
count(closure)
Range.count(closure)
Counts how many elements match the boolean closure
find(closure)
Range.find(closure)
Answers the number of the range that satisfies a given condition.
throws ElementNotFoundException if no element matched the given predicate
findOrElse(closure, continuation)
Range.findOrElse(closure, continuation)
Finds the first number matching the boolean closure,
or evaluates the continuation block closure if no element is found
findOrDefault(predicate, value)
Range.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.
sortedBy(closure)
Range.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
toString()
Range.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
apply(parameters)
Closure.apply(parameters)
Evaluates this closure passing its parameters
toString()
Closure.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 | |
const property tuesday | |
const property wednesday | |
const property thursday | |
const property friday | |
const property saturday | |
const property sunday | |
const property daysOfWeek |
Comportamiento
today()
calendar.today()
yesterday()
calendar.yesterday()
tomorrow()
calendar.tomorrow()
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 | |
const property month | |
const property year |
Comportamiento
toString()
Date.toString()
==(_aDate)
Date.==(_aDate)
Two dates are equals if they represent the same date
plusDays(_days)
Date.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).
plusMonths(_months)
Date.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).
plusYears(_years)
Date.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).
isLeapYear()
Date.isLeapYear()
Checks if the year is a leap year, like 2000, 2004, 2008...
dayOfWeek()
Date.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.
internalDayOfWeek()
Date.internalDayOfWeek()
Answers the day of week of the Date, where
1 = MONDAY
2 = TUESDAY
3 = WEDNESDAY
...
7 = SUNDAY
-(_aDate)
Date.-(_aDate)
Answers the difference in days between two dates, assuming self is minuend and _aDate is subtrahend.
minusDays(_days)
Date.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).
minusMonths(_months)
Date.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).
minusYears(_years)
Date.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).
<(_aDate)
Date.<(_aDate)
>(_aDate)
Date.>(_aDate)
<=(_aDate)
Date.<=(_aDate)
>=(_aDate)
Date.>=(_aDate)
between(_startDate, _endDate)
Date.between(_startDate, _endDate)
Answers whether self is between two dates (both inclusive comparison)
shortDescription()
Date.shortDescription()
Shows a short, internal representation of a date
(the result varies depending on user's locale)
isWorkDay()
Date.isWorkDay()
Answer whether the day is a work day (between monday and friday)
isWeekendDay()
Date.isWeekendDay()
Answer whether the day is a weekend day (saturday or sunday)
Singleton io
Represents an Input/Output event handler.
since 1.9.2
Estado
Atributo | WollokDoc |
---|---|
const property eventHandlers | // TODO: merge handlers |
const property timeHandlers | |
const property collitionHandlers | |
property eventQueue | |
property currentTime | |
property exceptionHandler | |
property domainExceptionHandler |
Comportamiento
queueEvent(event)
io.queueEvent(event)
Adds given event to the eventQueue.
eventHandlersFor(event)
io.eventHandlersFor(event)
Returns a list of callbacks for the given event.
If the given event is not in the eventHandlers, it is added.
addEventHandler(event, callback)
io.addEventHandler(event, callback)
Adds given callback to the given event.
removeEventHandler(event)
io.removeEventHandler(event)
Removes given event from the eventHandlers.
timeHandlers(name)
io.timeHandlers(name)
Returns a list of callbacks for the given time event.
If the given time event is not in the timeHandlers, it is added.
containsTimeEvent(name)
io.containsTimeEvent(name)
Returns if given time event it's in the timeHandlers.
addTimeHandler(name, callback)
io.addTimeHandler(name, callback)
Adds given callback to the given time event.
removeTimeHandler(name)
io.removeTimeHandler(name)
Removes given event from the eventHandlers.
collitionHandlersFor(event)
io.collitionHandlersFor(event)
Returns a list of callbacks for the given event.
If the given event is not in the collitionHandlers, it is added.
addCollitionHandler(event, callback)
io.addCollitionHandler(event, callback)
Adds given callback to the given event.
removeCollitionHandler(event)
io.removeCollitionHandler(event)
Removes given event from the collitionHandlers.
clear()
io.clear()
Removes all events from handlers.
flushEvents(time)
io.flushEvents(time)
Runs all events in the eventQueue that are in the eventHandlers
then all time events in the timeHandlers for the given time
finally, processes all collition events
runHandler(callback)
io.runHandler(callback)
Runs the given callback.
lib.wlk
Singleton console
Console is a global wollok object that implements a character-based console device
called "standard input/output" stream
Comportamiento
println(obj)
console.println(obj)
Prints a String with end-of-line character
readLine()
console.readLine()
Reads a line from input stream
readInt()
console.readInt()
Reads an int character from input stream
newline()
console.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 | |
const property actual |
Singleton assert
Assert object simplifies testing conditions
Comportamiento
that(value)
assert.that(value)
Tests whether value is true. Otherwise throws an exception.
notThat(value)
assert.notThat(value)
Tests whether value is false. Otherwise throws an exception.
see assert#that(value)
equals(expected, actual)
assert.equals(expected, actual)
Tests whether two values are equal, based on wollok ==, != methods
notEquals(expected, actual)
assert.notEquals(expected, actual)
Tests whether two values are equal, based on wollok ==, != methods
doesNotThrowException(block)
assert.doesNotThrowException(block)
Tests that a block does not throw any kind of exception. Block expects no parameters.
throwsException(block)
assert.throwsException(block)
Tests whether a block throws an exception. Otherwise an exception is thrown.
throwsExceptionLike(exceptionExpected, block)
assert.throwsExceptionLike(exceptionExpected, block)
Tests whether a block throws an exception and this is the same expected.
Otherwise an exception is thrown.
throwsExceptionWithMessage(errorMessage, block)
assert.throwsExceptionWithMessage(errorMessage, block)
Tests whether a block throws an exception and it has the error message as is expected.
Otherwise an exception is thrown.
throwsExceptionWithType(exceptionExpected, block)
assert.throwsExceptionWithType(exceptionExpected, block)
Tests whether a block throws an exception and this is the same exception class expected.
Otherwise an exception is thrown.
throwsExceptionByComparing(block, comparison)
assert.throwsExceptionByComparing(block, comparison)
Tests whether a block throws an exception and compare this exception with other block
called comparison. Otherwise an exception is thrown. The block comparison
receives a value (an exception thrown) that is compared in a boolean expression
returning the result.
fail(message)
assert.fail(message)
Throws an exception with a custom message.
Useful when you reach code that should not be reached.
equals(value)
assert.equals(value)
This method avoids confusion with equals definition in Object
Class StringPrinter
Estado
Atributo | WollokDoc |
---|---|
buffer |
Comportamiento
println(obj)
StringPrinter.println(obj)
getBuffer()
StringPrinter.getBuffer()
game.wlk
Singleton game
Wollok Game main object
Estado
Atributo | WollokDoc |
---|---|
const visuals | Collection of visual objects in the game |
property running | Is Game running? |
property errorReporter |
Comportamiento
initialize()
game.initialize()
addVisual(positionable)
game.addVisual(positionable)
Adds an object to the board for drawing it.
Object should understand a position property
(implemented by a reference or getter method).
addVisualCharacter(visual)
game.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).
removeVisual(visual)
game.removeVisual(visual)
Removes an object from the board for stop drawing it.
hasVisual(visual)
game.hasVisual(visual)
Verifies if an object is currently in the board.
allVisuals()
game.allVisuals()
Returns all visual objects added to the board.
whenKeyPressedDo(event, action)
game.whenKeyPressedDo(event, action)
Adds a block that will be executed each time a specific key is pressed
see keyboard.onPressDo()
whenCollideDo(visual, action)
game.whenCollideDo(visual, action)
Adds a block that will be executed while the given object collides with other.
Two objects collide when are in the same position.
The block should expect the other object as parameter.
onCollideDo(visual, action)
game.onCollideDo(visual, action)
Adds a block that will be executed exactly when the given object collides with other.
Two objects collide when are in the same position.
The block should expect the other object as parameter.
onTick(milliseconds, name, action)
game.onTick(milliseconds, name, action)
Adds a block with a specific name that will be executed every n milliseconds.
Block expects no argument.
Be careful not to set it too often :)
schedule(milliseconds, action)
game.schedule(milliseconds, action)
Adds a block that will be executed in n milliseconds.
Block expects no argument.
removeTickEvent(event)
game.removeTickEvent(event)
Remove a tick event created with onTick message
onSameCell(position1, position2)
game.onSameCell(position1, position2)
Verifies if two positions are on the same cell of the board
getObjectsIn(position)
game.getObjectsIn(position)
Returns all objects in given position.
say(visual, message)
game.say(visual, message)
Draws a dialog balloon with given message in given visual object position.
clear()
game.clear()
Removes all visual objects in game and configurations (colliders, keys, etc).
colliders(visual)
game.colliders(visual)
Returns all objects that are in same position of given object.
currentTime()
game.currentTime()
Returns the current Tick.
flushEvents(time)
game.flushEvents(time)
Runs all time event for the given time.
uniqueCollider(visual)
game.uniqueCollider(visual)
Returns the unique object that is in same position of given object.
stop()
game.stop()
Stops render the board and finish the game.
start()
game.start()
Starts render the board in a new windows.
at(x, y)
game.at(x, y)
Returns a position for given coordinates.
origin()
game.origin()
Returns the position (0,0).
center()
game.center()
Returns the center board position (rounded down).
title(title)
game.title(title)
Sets game title.
title()
game.title()
Returns game title.
width(width)
game.width(width)
Sets board width (in cells).
width()
game.width()
Returns board width (in cells).
height(height)
game.height(height)
Sets board height (in cells).
height()
game.height()
Returns board height (in cells).
ground(image)
game.ground(image)
Sets cells background image.
cellSize(size)
game.cellSize(size)
Sets cells size.
doCellSize(size)
game.doCellSize(size)
private
boardGround(image)
game.boardGround(image)
Sets full background image.
hideAttributes(visual)
game.hideAttributes(visual)
Attributes will not show when user mouse over a visual component.
Default behavior is to show them.
showAttributes(visual)
game.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)
game.sound(audioFile)
Returns a sound object. Audio file must be a .mp3, .ogg or .wav file.
tick(interval, action, execInmediately)
game.tick(interval, action, execInmediately)
Returns a tick object to be used for an action execution over interval time.
The interval is in milliseconds and action is a block without params.
Class AbstractPosition
Represents a position in a two-dimensional gameboard.
It is an immutable object since Wollok 1.8.0
Comportamiento
x()
AbstractPosition.x()
y()
AbstractPosition.y()
createPosition(x, y)
AbstractPosition.createPosition(x, y)
right(n)
AbstractPosition.right(n)
Returns a new Position n steps right from this one.
left(n)
AbstractPosition.left(n)
Returns a new Position n steps left from this one.
up(n)
AbstractPosition.up(n)
Returns a new Position n steps up from this one.
down(n)
AbstractPosition.down(n)
Returns a new Position, n steps down from this one.
say(element, message)
AbstractPosition.say(element, message)
Draw a dialog balloon with given message in given visual object position.
allElements()
AbstractPosition.allElements()
//TODO: Implement native
clone()
AbstractPosition.clone()
Returns a new position with same coordinates.
distance(position)
AbstractPosition.distance(position)
Returns the distance between given position and self.
clear()
AbstractPosition.clear()
Removes all objects in self from the board for stop drawing it.
==(other)
AbstractPosition.==(other)
Two positions are equals if they have same coordinates.
toString()
AbstractPosition.toString()
String representation of a position
round()
AbstractPosition.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 | |
const y |
Comportamiento
x()
Position.x()
y()
Position.y()
createPosition(_x, _y)
Position.createPosition(_x, _y)
Class MutablePosition
Keyboard object handles all keys movements. There is a method for each key.
Estado
Atributo | WollokDoc |
---|---|
x | |
y |
Comportamiento
x()
MutablePosition.x()
y()
MutablePosition.y()
createPosition(_x, _y)
MutablePosition.createPosition(_x, _y)
goRight(n)
MutablePosition.goRight(n)
goLeft(n)
MutablePosition.goLeft(n)
goUp(n)
MutablePosition.goUp(n)
goDown(n)
MutablePosition.goDown(n)
Singleton keyboard
Keyboard object handles all keys movements. There is a method for each key.
Comportamiento
any()
keyboard.any()
num(n)
keyboard.num(n)
letter(l)
keyboard.letter(l)
arrow(a)
keyboard.arrow(a)
num0()
keyboard.num0()
num1()
keyboard.num1()
num2()
keyboard.num2()
num3()
keyboard.num3()
num4()
keyboard.num4()
num5()
keyboard.num5()
num6()
keyboard.num6()
num7()
keyboard.num7()
num8()
keyboard.num8()
num9()
keyboard.num9()
a()
keyboard.a()
b()
keyboard.b()
c()
keyboard.c()
d()
keyboard.d()
e()
keyboard.e()
f()
keyboard.f()
g()
keyboard.g()
h()
keyboard.h()
i()
keyboard.i()
j()
keyboard.j()
k()
keyboard.k()
l()
keyboard.l()
m()
keyboard.m()
n()
keyboard.n()
o()
keyboard.o()
p()
keyboard.p()
q()
keyboard.q()
r()
keyboard.r()
s()
keyboard.s()
t()
keyboard.t()
u()
keyboard.u()
v()
keyboard.v()
w()
keyboard.w()
x()
keyboard.x()
y()
keyboard.y()
z()
keyboard.z()
alt()
keyboard.alt()
backspace()
keyboard.backspace()
control()
keyboard.control()
del()
keyboard.del()
center()
keyboard.center()
down()
keyboard.down()
left()
keyboard.left()
right()
keyboard.right()
up()
keyboard.up()
enter()
keyboard.enter()
minusKey()
keyboard.minusKey()
plusKey()
keyboard.plusKey()
shift()
keyboard.shift()
slash()
keyboard.slash()
space()
keyboard.space()
Class Key
Wollok Game Sound object
Estado
Atributo | WollokDoc |
---|---|
const property keyCodes |
Comportamiento
onPressDo(action)
Key.onPressDo(action)
Adds a block that will be executed always self is pressed.
Class Sound
Wollok Game Sound object
Estado
Atributo | WollokDoc |
---|---|
const property file |
Comportamiento
initialize()
Sound.initialize()
play()
Sound.play()
Plays the file's sound.
A sound can only be played once.
played()
Sound.played()
Answers whether the sound has been played or not.
stop()
Sound.stop()
Stops playing the sound and disposes resources.
pause()
Sound.pause()
Pauses the sound.
Throws error if the sound is already paused or if the sound hasn't been played yet.
resume()
Sound.resume()
Resumes playing the sound.
Throws error if the sound is not paused.
paused()
Sound.paused()
Answers whether the sound is paused or not.
volume(newVolume)
Sound.volume(newVolume)
Changes absolute volume, values must be between 0 and 1.
volume()
Sound.volume()
Answers the volume of the sound.
shouldLoop(looping)
Sound.shouldLoop(looping)
Sets whether the sound should loop or not.
shouldLoop()
Sound.shouldLoop()
Answers whether the sound is set to loop or not.
Class Tick
Estado
Atributo | WollokDoc |
---|---|
interval | Milliseconds to wait between each action |
const name | The ID associated to the tick event to be created |
const action | |
const inmediate | Indicates whether the action will be executed as soon as the loop starts, or it will wait to the first time interval. |
Comportamiento
start()
Tick.start()
stop()
Tick.stop()
Stops looping the tick.
reset()
Tick.reset()
Stops and starts looping the tick.
interval(milliseconds)
Tick.interval(milliseconds)
Updates the tick's loop interval.
isRunning()
Tick.isRunning()
Indicates whether the tick is currently looped or not.
mirror.wlk
Class InstanceVariableMirror
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 target | |
const property name |
Comportamiento
value()
InstanceVariableMirror.value()
valueToString()
InstanceVariableMirror.valueToString()
toString()
InstanceVariableMirror.toString()
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 |
Comportamiento
resolve(attributeName)
ObjectMirror.resolve(attributeName)
Accesses a variable by name, in a reflexive way.
instanceVariableFor(name)
ObjectMirror.instanceVariableFor(name)
Retrieves a specific variable for target object. Expects a name
instanceVariables()
ObjectMirror.instanceVariables()
Answers a list of instance variables for target object
vm.wlk
Singleton runtime
Object for Wollok implementation for runtime decisions
Comportamiento
isInteractive()
runtime.isInteractive()
true if running REPL, false otherwise