PonderTalk Basic Types
In addition to Managed Objects that have a command interface there are several basic, built-in objects that can be manipulated and given to Managed Objects as arguments. They are:
Name |
Description |
A collection of named objects c.f. Perl hash, Java Map, Smalltalk dictionary |
|
An integer or real number |
|
An array of other objects |
|
A string value |
|
A true or false value |
|
The null value |
|
An XML structure |
Some of the following examples make use of special operations available on the root domain of the SMC. These include import and print, please see the root domain documentation for these operations.
String
Strings are created in PonderTalk with double-quotes e.g.
1 myString := "A string"
Operations
Operation |
Result Type |
Description |
Example |
+ object |
String |
Returns a new string being the concatenation of the original string and the object as a string |
"S1" + "S2" => "S1S2" |
* number |
String |
Returns a new string being the concatenation of number copies of the original string |
"S1" * 3 => "S1S1S1" |
More operations to do sub-strings and regexp will be added. If an operation is expecting a Boolean then the String value "true" becomes true and the String value "false" becomes false otherwise an error is created. See the string documentation for all operations available.
Block
A block is an object that contains code. It behaves rather like a function with zero or more arguments. When a block is executed it returns the value of the last statement executed. The result of the last statement becomes the result of the block. Blocks may be created in PonderTalk with square brackets e.g.
1 // A block with no arguments, this will return 7
2 [ myNum := 3 * 4 ]
3 // A block with two arguments, this will return the result of arg1 + arg2
4 [ :arg1 :arg2 | arg1 + arg2 ]
Blocks are executed by sending them value messages. value if there are no arguments, value: if there is one argument, value:value: for two arguments etc. etc.
Operations
Operation |
Result Type |
Description |
Example |
value |
Object |
Executes the statements inside the block |
[ "Hello," ] value => "Hello," |
value: arg |
Object |
Executes the statements inside the block with arg being given as the block's argument |
[ :arg | "Hello," + arg ] value: "World!" => "Hello, World!" |
value: arg1 value: arg2 |
Object |
Executes the statements with arg1 and arg2 being given as the block's arguments |
[ :arg1 :arg2 | "Hello," * arg1 + arg2 ] value: 2 value: "World!" |
See the block documentation for all operations available.
Boolean
Booleans are created in PonderTalk with the special keywords true and false e.g.
1 myBoolean := true.
2 myBoolean := false.
Operations
Operation |
Result Type |
Description |
Example |
ifTrue: Block |
answer the result of the block or Nil |
Execute the block (with no parameters) if the boolean is true |
myBoolean ifTrue: [ root print "true" ] |
ifFalse: Block |
answer the result of the block or Nil |
Execute the block (with no parameters) if the boolean is false |
myBoolean ifFalse: [ root print "false" ] |
ifTrue: BlockT ifFalse: BlockF |
answer the result of one of the blocks |
Execute BlockT if the boolean is true else BlockF. Neither block will receive arguments |
myBoolean ifTrue: [ root print "true" ] ifFalse: [ root print "false" ] |
ifFalse: BlockF ifTrue: BlockT |
answer the result of one of the blocks |
Execute BlockT if the boolean is true else BlockF. Neither block will receive arguments |
myBoolean ifFalse: [ root print "false" ] ifTrue: [ root print "true" ] |
not |
Boolean |
returns the inverse of the boolean value |
myBoolean := myBoolean not |
& Boolean |
Boolean |
return the value of the two booleans joined with and |
myBoolean := boolean1 & true |
| Boolean |
Boolean |
return the value of the two booleans joined with or |
myBoolean := boolean1 | true |
and: aBlock |
Boolean |
Return false if the boolean is false else return result of the block. The block is not executed if the boolean is false |
myBoolean and: [ 4 < 5 ] |
or: aBlock |
Boolean |
Return false if the boolean is false else return result of the block. The block is not executed if the boolean is true |
myBoolean or: [ 4 < 5 ] |
See the boolean documentation for all operations available.
Array
Arrays hold an ordered collection of Managed Objects. The contained objects are not typed. Arrays are created from other operations like collect:. They may also be created with PonderTalk in the following manner:
1 // Create an empty array
2 anArray := #().
3 // Create an array with a variety of elements
4 array := #( 5 "20" root/factory/ecapolicy true ).
5 // Obtain an array as a result of a messag
6 anotherArray := root/factory list.
Operations
Operation |
Result Type |
Description |
Example |
at: aNumber |
Object |
Return the object at index aNumber |
myObj := root at: 5 |
do: Block |
self |
For each object call the block with the object as an argument. Only the last block's statement return value is returned |
#( 1 2 3 ) do: [ :value | account add: value ] |
collect: Block |
Array |
For each object in the arraycall the block with the the object as an argument. An array of all the block's return values is returned |
array := #( 1 2 3 4 5 6 7 8 9 10 ). |
See the array documentation for all operations available.
Hash
Hashs are created in PonderTalk from other operations. Domains and Events are actually Hashs
1 // Use an array to create an empty hash
2 aHash := #() asHash.
3 // or a domain
4 anotherHash := root/factory asHash.
Operations
Operation |
Result Type |
Description |
Example |
at: "name" |
an object |
Return the object at entry "name" |
myObj := root at: policy |
at: "name" put: Object |
Object |
Put object into the hash and call it "name" and return the object |
root at: "fred" put: myObj |
do: Block |
value of last block executed |
For each name/value pair call the block with the two arguments. Only the last block's statement return value is returned |
root do: [ :name :value | root print: name ] |
collect: Block |
Array |
For each name/value pair call the block with the two arguments. An array of all the blocks' return values is returned |
allObjs := root collect: [ :name :object | object]. |
See the hash documentation for all operations available.
Xml
The Xml basic type holds an XML structure. The structure may be manipulated using XPath commands sent to the structure as PonderTalk messages. The Xml type is created from a String using the asXML unary message. Note: In the following example single quote characters (') have been used within the XML. This is valid XML and means that double quote characters (") do not have to be escaped.
1 // Create an Xml basic object
2 xml := "<element attr1='a1' ><child>Some text</child></element>" asXML.
Operations
Operation |
Result Type |
Description |
Example |
xpathNumber: "expression" |
number |
Return a number from the structure |
num := xml xpathNumber: "@attr1" |
xpathString: "expression" |
string |
Return a string from the structure |
string := xml xpathString: "@attr1" |
xpathNode: "expression" |
Xml |
Return xml struct from the structure |
xml1 := xml xpathNode: "child" |
xpathNodeSet: "expression" |
Array |
Return xml structs from the structure |
array := xml xpathNodeSet: "childName" |
1 // Handle incoming events
2 eventHandler := [ :string |
3 root print: "New event received from ISL".
4 root print: string.
5
6 // Convert to an XML object
7 xml := string asXML.
8
9 topic := xml xpathString: "/esiievent/@topic".
10 event := xml xpathNode: "/esiievent/event".
11 //root print: "Event is " + event.
12 eventName := event xpathString: "@name".
13 root print: "topic is " + topic + " " + eventName.
14
15 response := event xpathString: "response/@key".
16 root print: "response is " + response.
17
18 hash := getAttributes value: event .
19 hash at: "response" put: response.
20
21 root print: "Sending event "+eventName+" internally".
22 (root/esii/event at: eventName) fromHash: hash.
23
24 ].
25 root/esii at: "eventHandler" put: eventHandler.
See the XML documentation for all operations available.
