Introduction to Mindscript

Why Mindscript Language

For security reasons, we did not allow the execution of a script (or DSL) inside the Reasoning Engine. Therefore, selection class evaluation is done on Webhook and sends the result in JSON, and extract “selection term” from the JSON using JSONPath. The selection class evaluates the extracted value with the “selection term” in the configuration. We see more limitations without interfacing with Webhook, such as:

  • value formatting (response or Webhook request POST JSON payload),

  • value evaluation (parameter or Webhook JSON response), and

  • simple boolean logic operations (parameter or Webhook JSON response).

There should be no security compromise.

Introduction

  • Mindscript is a fully object-oriented, dynamically typed, reflective programming language with no non-object types

  • Mindscript was created as the language to underpin the Mind Expression of computing exemplified by human–computer symbiosis

Everything is an object

  • Integers are instances of one of the numeric classes

  • Classes are instances of the class Metaclass and are just as manipulable as any other object

  • All classes are part of a single class tree; no disjoint class trees

  • There are no pointers into memory locations that you can dereference and mess with

  • Functions are not called and messages are sent to objects

Work is done by sending messages to objects, which decide how to respond to that message and run a method as a result, which eventually returns some object to the original message sending code.

The system knows the class of the object receiving a message and looks up the message in that class’s list of methods. If it is not found, the lookup continues in the super class until either it is found or the root of the classes is reached and there is still no relevant method.

Syntax

Mindscript code does only two things:

  • assign variables and

  • send messages.

To assign variable, we use operator :=

date := '2022-10-16'.

The other basic operation is to send a message to an object

anObject aMessage

There are three sorts of messages.

  • Unary - a single symbol that may be several words conjoined in what we call camelcase form, with no arguments. For example size, newEmptyDB, current

  • Binary - a small set of symbols often used for arithmetic operations in most languages, requiring a single argument. For example +, //, @

    We support traditional arithmetic precedence, which is different with other smalltalk dialects.

    For example, for the following expression\

    1+2*3 "returns 7 instead of 9"ll
  • Keyword - the general form where multiple arguments can be passed. As with the unary form we use camelcase to join words together but arguments are inserted in the midst of the message with colons used to separate them lexically. For example at: put:, at:

Please note that in an expression for an object, unary message is precedent than binary message, and binary message is precedent than keyword message.

For example, for the following expression:

12 abs + -12 abs raisedTo: 3. 

It executes based on their message types priority likes this:

((12 abs) + (-12 abs)) raisedTo: 3. 

Example

num1 := num1 asInteger.
num2 := num2 asInteger.
num1 + num2

Allowable characters

  • a-z

  • A-Z

  • 0-9

  • .+/*~<>@%|&?

  • blank, tab, cr, ff, lf

Variables

  • variable names are untyped

  • reserved names: nil, true, false, self, super, and thisContext

Variable scope

  • Global: installed by the engine and can be used anywhere, for example global class Parameter.

  • Special (reserved): super, self, true, false, nil.

  • Method Temporary: local to a method

  • Block Temporary: local to a block

  • Block Parameters: automatic block temp vars that name the incoming parameters. Cannot be assigned to

Comments

"Comments are enclosed in quotes and may be arbitrary length"
"
You can quote double quotation mark by adding ! before it.
!"
"

Statement Separator

  • Period (.) is the statement separator

  • Not required on last line of a method

  • To execute multiple statements we must separate them by .

  • For example we execute the following two statements one by one based on statement separator.

aNumber := -12 abs.
Parameter at: 'key' put: aNumber.

Assignment

"Assign x with 5"
x := 5.
"Assign x,y,z with 6"
x := y := z := 6.
"Assign a with a parameter value in current conversation."
a := Parameter at: 'test'.

Constants

"true constant"
b := true.
"false constant"
b := false.
"nil object constant"
x := nil.
"integer constants"
x := 1.
x := 1e10.
x := 3.14.
x := 3.14e-10.
"String constants"
x := 'Hello'.
"String constants with single quote escape. Two '' means one ' in a string."
x := 'There''s a problem with my television'.
"character constant"
x := $A.
"symbol constants"
x := #aSymbol.
x := #'a-symbol'.
"Keyword symbol"
x := #:en.
"Keyword symbol"
x := #':en'.
"array constants, mixing of types allowed"
x := #('abc' 2 $a).

Blocks

  • Blocks are objects and may be assigned to a variable

  • Value is last expression evaluated unless explicit return

  • Blocks may be nested

  • Specification [ arguments | | localvars | expressions ]

  • ^ expression terminates block & method (exits all nested blocks)

"simple block usage"
x := [ y := 1. z := 2 ].
x value.

"set up block with argument passing"
x := [ :argOne :argTwo |  argOne, ' and ' , argTwo].      
"use block with argument passing"
Console print: (x value: 'First' value: 'Second')

Method Calls

  • Unary methods are messages with no arguments

  • Binary methods

  • Keyword methods are messages with selectors including colons standard categories/protocols:

  • In an expression for an object, unary message is precedent than binary message, and binary message is precedent than keyword message.

"unary message"
a := -12 abs.
"Binary message"
1+1
"keyword messaage"
a := Parameter at: 'test'.

Array

"Construct an array by evaluation each statement."
{ 1. 2. 3 }
"Multiple dimensions array."
{{ 1. 2. 3 }.
 { 4. 5. 6 }
 }

Associations

"binary message -> will construct an association list for two objects."
(#primary -> 'The television has no signal')

Dictionary

a := Dictionary new.
a at: 'key' put: 30.
(a at: 'key') = 30.

Last updated