Package: Kernel-Objects
Class: APIError
Introduction
Environment: container
APIError is a class to interact with error object returned by Engine.
An APIError object has the following attributes:
code: the error code
args: the arguments of the error
detail: the detailed message of the error
For example:
Instance Method
Category: accessing
args
- Get error args.code
- Get error code.detail
- Get error detail message.
Class: Boolean
Introduction
Environment: container
Boolean is a subclass of Object. It has two instances: true
and false
.
We can use the ifTrue:
and ifFalse:
methods to evaluate a block depending on the value of the receiver.
We can also use the and:
and or:
methods to evaluate a block depending on the value of the receiver.
Class: CSVReader
Introduction
Environment: container
This is a class to read CSV into Mindscript array.
For example:
Class Method
Category: convenience
fromString:
- Read a CSV string and return an array.For example:
Class: Character
Introduction
Environment: container
A Character can represent any single character from the Unicode character set.
We can create a character by using the literal syntax, which is a single character enclosed in single quotes. For example:
In this example, aCharacter is an instance of Character representing the uppercase letter A
.
We can also create a character by using the integer value of a character. For example:
Class Method
Category: accessing untypeable characters
cr
- Answer the character representing a carriage return.lf
- Answer the character representing a linefeed.null
- Answer the character representing a null.space
- Answer the character representing a space.tab
- Answer the character representing a tab.
Category: instance creation
value:
- Answer the character whose value is an integer.For example:
Instance Method
Category: converting
asCharacter
- Answer the receiver itself.For example:
asInteger
- Answer the receiver's character code.For example:
asLowercase
- If the receiver is uppercase, answer its matching lowercase Character.For example:
asString
- Answer the receiver as a string.For example:
asUppercase
- If the receiver is lowercase, answer its matching uppercase Character.For example:
Class: Dictionary
Introduction
Environment: container
A dictionary is a collection of elements that associate a key object with a value object. It can be viewed as a set of associations.
It is used when you need a collection of objects which can be accessed with a key. For example, if you associate some words with a definition, the word will be the key and the definition will be the value. Both of them can be any kind of objects.
Associations are used to fetch the value using a key ( key -> value).
Following common used methods:
new
create a new dictionary.size
return the size of the dictionary.keys
return the keys of the dictionary.at:
get the value associated with the given key.at:put:
set the value associated with the given key.asDictionary
return a dictionary containing the elements of the receiver.
Class Method
Category: instance creation
new
- answer a new Dictionary.
Instance Method
Category: accessing
add:
- Add the newObject (association) to the receiver.For example:
addAll:
- Adding all elements of a Dictionary to the receiver, which is the primary Dictionary.For example:
associationAt:
- Answer the value associated with the given key.For example:
associationAt:ifAbsent:
- Answer the key/value Association for the given key. Evaluate aBlock (answering the result) if the key is not found.For example:
associations
- Answer with all associations in the Dictionary, as a List.For example:
at:
- answer the value associated with the given key.at:ifAbsent:
- Get the value of the parameter with specified name, and specify a default value if absent. The parameter for the default value can bea code block, which will be evaluated if the parameter is absent.
a value, which will be returned if the parameter is absent.
For example:
at:ifAbsentPut:
- Answer the value associated to the given key. If the key is not found, evaluate aBlock and associate the result to aKey before returning.For example:
at:ifPresent:
- If aKey is absent, answer nil. Else, evaluate aBlock passing the associated value and answer the result of the invocation.For example:
at:put:
- Set the value associated with the given key.atAll:
- Answer with the values associated with the given keys.For example:
keyAtValue:
- Answer the key associated to the given value, or nil if the value is not found.For example:
keyAtValue:ifAbsent:
- Answer the key associated to the given value. Evaluate exceptionBlock (answering the result) if the value is not found.For example:
keys
- answer keys as an array in the receiver.size
- answer the number of associations in the receiver.values
- answer dictionary values as an array in the receiver.
Category: enumerating
associationsDo:
- Pass each association in the dictionary to aBlock.For example:
collect:
- Evaluate the given block for each element of the receiver and return a new Dictionary with the results.For example:
detect:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. Answer the first element for which aBlock evaluates to true.For example:
detect:ifFound:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. If some element evaluates aBlock to true, then cull this element into foundBlock and answer the result of this evaluation.For example:
detect:ifFound:ifNone:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. If some element evaluates aBlock to true, then cull this element into foundBlock and answer the result of this evaluation. If none evaluate to true, then evaluate exceptionBlockFor example:
detect:ifNone:
- Evaluate aBlock with each of the receiver's elements as the argument until aBlock evaluates to true. Answer the first element for which aBlock evaluates to true, or answer the value in none block.For example:
do:
- Evaluate the given block for each element of the receiver.Each element is an association, so the block should accept two arguments, the key and the value.
For example:
keysDo:
- Pass each key in the dictionary to aBlock.For example:
reject:
- Answer a new dictionary containing the key/value pairs for which aBlock returns false. aBlock only receives the value part of the pairs.For example:
select:
- Answer a new dictionary containing the key/value pairs for which aBlock returns true. aBlock only receives the value part of the pairs.For example:
valuesCollect:
- Answer a new dictionary where the keys are the same and the values are obtained by passing each value to aBlock and collecting the return values.For example:
valuesDo:
- Pass each value in the dictionary to aBlock.For example:
Category: removing
remove:
- Remove anAssociation’s key from the dictionary.For example:
remove:ifAbsent:
- Remove anAssociation’s key from the dictionary, if absent call aBlock with the association.For example:
removeAllKeys:
- Remove all the keys in keys, without raising any errors.For example:
removeAllKeys:ifAbsent:
- Remove all the keys in keys, passing the missing keys as parameters to aBlock as they’re encountered.For example:
removeKey:
- Remove the association for the given key.removeKey:ifAbsent:
- Remove the association for the given key, if absent call aBlock with the key.For example:
Category: testing
includes:
- Answer whether the receiver contains anObject as one of its values.includesAssociation:
- Answer whether the receiver contains the key which is anAssociation’s key and its value is anAssociation’s value.includesKey:
- Answer true if the receiver includes the given key.For example:
occurrencesOf:
- Answer the number of occurrences of aValue as one of the receiver’s values.For example:
Class: JSONReader
Introduction
Environment: container
This is a class to read JSON into Mindscript objects.
For example:
Class Method
Category: convenience
fromString:
- Read a JSON string and return a Mindscript object.Return
nil
if the string is empty.
Class: ProtoObject
Introduction
Environment: container
ProtoObject establishes minimal behavior required of any object in Engine.
ProtoObject has no instance variables, nor should any be added.
One of the most important methods of ProtoObject is subclass:, which is used to create new classes.
And for each object, they have the following default attributes that are implmented in ProtoObject:
name
the name of the objectclass
the class of the objectcomment
the comment of the object
Instance Method
Category: accessing
className
- Answer the class name of the object.For example:
nestedAt:
- answer the element associated with the given nested keys.The keys are an array of strings to represent recursive keys in nested dictionaries.
For example, let's say object
x
has attributea
, which is another object has an attributeb
, then you can get the value ofb
like this:For an array or a list, its attributes are indexes of them basing on 1.
If the key is not found, return nil.
nestedAt:ifAbsent:
- answer the element associated with the given key.The keys are an array of strings to represent recursive keys in nested dictionaries.
For example, let's say object
x
has attributea
, which is another object has an attributeb
, then you can get the value ofb
with default value0
like this:For an array or a list, its attributes are indexes of them basing on 1.
If the key is not found, then return the value in default-value, which can be:
a code block or
a value.
Category: combining
,
- Concatenate two objects.->
- answer an Association between self and an object.For example:
Category: comparing
!=
- Primitive. This answers whether the receiver and the argument are not equal.=
- Primitive. This answers whether the receiver and the argument are equal.==
- Primitive. This answers whether the receiver and the argument are the same object (have the same object pointer).
Category: converting
asArray
- Answer an array to represent an object.For example:
asDictionary
- answer a Dictionary by converting current object.asJson
- Convert the Mindscript object to JSON string.For example:
asString
- Converts an object into a string.For example:
Category: instance creation
new
- answer a new instance of the receiver's class.
Category: testing
ifNil:
- answer the result of evaluating the given block if the receiver is nil.For example:
ifNil:ifNotNil:
- If the receiver is not nil, pass it as argument to the ifNotNilBlock block. else execute the nilBlock block.For example:
ifNotNil:
- answer the result of evaluating the given block if the receiver is not nil.For example:
ifNotNil:ifNil:
- If the receiver is not nil, pass it as argument to the ifNotNilBlock block. else execute the nilBlock block.For example:
isDefined
- Whether an object is an UndefinedObject.isSequenceable
- Answer whether the receiver can be accessed by a numeric index with #at:/#at:put:.
Class: Random
Introduction
Environment: container
I can generate a random number.
For example, to generate a random number between 0 and 6:
Class Method
Category: convenience
between:and:
- Generate a random number between a range.For example, to generate a random number between 0 and 6:
Class: Talk
Introduction
Environment: container
My singleton is a central entry point to the system.
I can sleep for 3 seconds by Talk sleepForSeconds: 3
.
Class Method
Category: system
sleepForSeconds:
- sleep for several seconds.For example:
Class: UndefinedObject
Introduction
Environment: container
I describe the behavior of an undefined variable.
You can determine whether a variable has been defined or not by sending the message isDefined
to any object. If the variable is undefined, you can expect a false
response to that message.
It's important to make sure that all variables are properly initialized before they are used, to avoid errors and unexpected behavior in your program.
This feature is extremely useful when establishing rules for a specific subject.
When a variable is defined within a subject, it can be used in another subject within the same conversation, assuming it was defined earlier.
This demonstrates that variables can be accessed at the conversation level.
Instance Method
Category: testing
isDefined
- Whether an object is an UndefinedObject.
Last updated