This documentation is work-in-progress, we are working very hard to improve it. If you wish to help: edit here (md).
Translations: Spanish, Dutch

Root Object

sections in this chapter:
catch-all-methods
programmatic-messages
[ Object ] type
[ Object ] code.
[ Object ] string
[ Object ] number
[ Object ] boolean
[ Object ] equals: [ Object ]
[ Object ] !=: [ Object ]
[ Object ] myself
[ Object ] recursive
[ Object ] do
[ Object ] done
[ Object ] copy
[ Object ] case: [ Object ] do: [ Code ]
[ Object ] message: [ String ] arguments: [ List ]
[ Object ] on: [ String ] do: [ Code ]
[ Object ] respond: [ String ]
[ Object ] respond: [ String ] and: [ String ]
[ Object ] None?
[ Object ] learn: [ String ] means: [ String ]

The object named Object is the root object of all objects in Xoscript and provides core language features.

The most frequently sent message is on:do:, which expands the functionalities of an object. This message is received by the root object, which consequently links the specified task to the message, and by doing so expands the derived object.

Catch-all methods

Normally if you send a message that does not correspond with a method in the object, it gets ignored. However, you can specify so-called magic methods or catch-all methods that will get invoked if the message is not understood by the object.

There are 4 catch-all methods available. Each message matches a specific number of arguments.

Catch-all message Number of arguments
respond: 0
respond:and: 1
respond:and:and: 2
respond:and:and:and: 3

Example:

>> HTML := Object new.
HTML on: ['respond:'] do: { :tag
Out write: (['<tag>'] tag: tag), stop.
}.
HTML on: ['respond:and:'] do: { :tag :html
Out write: (
['<tag>innerHTML</tag>']
tag: tag - [':'],
innerHTML: html
), stop.
}.
>> html := HTML new.
html body h1: ['header'].

Result:

<body>
<h1>header</h1>
automatically generated from test: #619

Programmatic messages

Instead of sending out a message directly to an object, it can also be sent via a variable. To do so, you use the message message:arguments:.

Example:


>> x := 5.
>> y := x message: ['×'] arguments: (List ← 2).
Out write: y, stop.

Result:

10
automatically generated from test: #396

[ Object ] type

Example:


>> x := Object.
Out write: x type, stop.
Out write: 777 type, stop.
Out write: ['ABC'] type, stop.
Out write: True type, stop.

Result:

Object
Number
String
Bool
automatically generated from test: #383

[ Object ] code.

Example:


>> x := Dict new.
x abc: 123.
>> y := List ← x.
Out write: y code, stop.

Result:

(List ← ((Dict new) put:123 at:['abc']))
automatically generated from test: #384

[ Object ] string

Example:


>> x := Object.
Out write: x string, stop.

Result:

Object
automatically generated from test: #385

[ Object ] number

Example:


>> x := Object.
Out write: x number, stop.

Result:

1
automatically generated from test: #386

[ Object ] boolean

Example:


>> x := Object.
Out write: x bool, stop.

Result:

True
automatically generated from test: #387

[ Object ] equals: [ Object ]

Example:


>> x := Object new.
>> y := Object new.
>> z := x.
Out write: ( x equals: y ), stop.
Out write: ( x equals: z ), stop.
Out write: ( x = y ), stop.
Out write: ( x = z ), stop.
Out write: ( x ≠ y ), stop.
Out write: ( x ≠ z ), stop.

Result:

False
True
False
True
True
False
automatically generated from test: #388

[ Object ] !=: [ Object ]

Example:


>> x := Object new.
>> y := Object new.
>> z := x.
Out write: ( x equals: y ), stop.
Out write: ( x equals: z ), stop.
Out write: ( x = y ), stop.
Out write: ( x = z ), stop.
Out write: ( x ≠ y ), stop.
Out write: ( x ≠ z ), stop.

Result:

False
True
False
True
True
False
automatically generated from test: #389

[ Object ] myself

Example:


Out write: Object myself, stop.
Out write: True bool, stop.
Out write: 123 number, stop.
Out write: ['x'] string, stop.

Result:

Object
True
123
x
automatically generated from test: #390

[ Object ] recursive

Example:


>> r := Object new.
r on: ['∞'] do: { :x
Out write: x, stop.
(x < 3) true: { self recursive ∞ (x + 1). }.
}.
r ∞ 1.

Result:

1
2
3
automatically generated from test: #391

[ Object ] do

Example:


>> x := List ← 1 ; 2 ; 3.
x do pop shift done.
Out write: x, stop.

Result:

List ← 2
automatically generated from test: #392

[ Object ] done

Example:


>> x := List ← 1 ; 2 ; 3.
x do pop shift done.
Out write: x, stop.

Result:

List ← 2
automatically generated from test: #393

[ Object ] copy

Example:


>> x := 1.
>> y := x.
>> z := x copy.
x add: 1.
Out write: x, stop.
Out write: y, stop.
Out write: z, stop.

Result:

2
2
1
automatically generated from test: #394

[ Object ] case: [ Object ] do: [ Code ]

Example:


>> x := ['**'].
x
case: ['*'] do: { Out write: 1. },
case: ['**'] do: { Out write: 2. },
case: ['***'] do: { Out write: 3. }.
Out stop.

Result:

2
automatically generated from test: #395

[ Object ] message: [ String ] arguments: [ List ]

Example:


>> x := 5.
>> y := x message: ['×'] arguments: (List ← 2).
Out write: y, stop.

Result:

10
automatically generated from test: #396

[ Object ] on: [ String ] do: [ Code ]

Example:


>> q := Object new.
q on: ['abc:'] do: { :p
own abc := p.
}.
q on: ['abc'] do: {
<- own abc.
}.
>> a := q new abc: ['123'].
Out write: a abc, stop.

Result:

123
automatically generated from test: #397

[ Object ] respond: [ String ]

Example:


>> x := Object new.
x on: ['respond:']  do: { :a
<- (a + ['!']).
}.
Out write: x abc.

Result:

abc!
automatically generated from test: #398

[ Object ] respond: [ String ] and: [ String ]

Example:

>> repeater := Object new.
repeater on: ['respond:'] do: { :what
Out write: what + [' '].
}.
repeater on: ['respond:and:'] do: { :what :say
Out write: what, write: say + [' '].
}.
repeater on: ['respond:and:and:'] do: { :what :say :more
Out write: what, write: say, write: more.
}.
repeater repeat.
repeater everything: ['I say.'].
repeater and: ['I '] everything: ['do.'].

Result:

repeat everything:I say. and:everything:I do.
automatically generated from test: #43

[ Object ] None?

Example:


Out write: Object None?, stop.

Result:

False
automatically generated from test: #401

[ Object ] learn: [ String ] means: [ String ]

Example:


Number learn: ['-'] means: ['+'].
Out write: 2 - 1, stop.

Result:

3
automatically generated from test: #402