this documentation is work-in-progress, edit here (md).

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:

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>

	

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

	

[ 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

	

[ 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']))

	

[ Object ] string

Example:


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

Result:

Object

	

[ Object ] number

Example:


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

Result:

1

	

[ Object ] boolean

Example:


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

Result:

True

	

[ 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

	

[ 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

	

[ 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

	

[ 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

	

[ Object ] do

Example:


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

Result:

List ← 2

	

[ Object ] done

Example:


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

Result:

List ← 2

	

[ 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

	

[ 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

	

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

Example:


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

Result:

10

	

[ 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

	

[ Object ] respond: [ String ]

Example:


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

Result:

abc!
	

[ 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.

	

[ Object ] None?

Example:


 Out write: Object None?, stop.
 
	

Result:

False

	

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

Example:


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

Result:

3