|
@@ -88,12 +88,24 @@ command {
|
|
print "second block"
|
|
print "second block"
|
|
}
|
|
}
|
|
|
|
|
|
-# In Muesli all values are typed. Types can be defined by the builtin type command.
|
|
|
|
-type Door ( object locked Bool keys Item[] )
|
|
|
|
|
|
+# In Muesli all values are typed. Types can be defined by the builtin type
|
|
|
|
+# command. User defined types always are derived from Object or from another
|
|
|
|
+# built in type. They add the fields mentioned with their given types.
|
|
|
|
+type Door Object name String locked Bool keys Int[]
|
|
|
|
+
|
|
|
|
+# A value of defined type can be created using the new command
|
|
|
|
+set door1 (new Door "red door" true [])
|
|
|
|
|
|
# Commands can be defined by the built in 'to' command.
|
|
# Commands can be defined by the built in 'to' command.
|
|
# They can have many arguments and many results.
|
|
# They can have many arguments and many results.
|
|
-to open[door Door key Item] Bool {
|
|
|
|
|
|
+to openDoor [door Door key Item] Bool {
|
|
|
|
+ if (contains (member door key) key) {
|
|
|
|
+ set (member door open) true
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+# Methods can be also defined with the to command
|
|
|
|
+to Door open [key Item] Bool {
|
|
if (contains (member door key) key) {
|
|
if (contains (member door key) key) {
|
|
set (member door open) true
|
|
set (member door open) true
|
|
}
|
|
}
|
|
@@ -113,7 +125,7 @@ to open[door Door key Item] Bool {
|
|
# To create such an overload you should create a "cover" with the builtin
|
|
# To create such an overload you should create a "cover" with the builtin
|
|
# cover command. Covers are commands that dispatch to other commands based on
|
|
# cover command. Covers are commands that dispatch to other commands based on
|
|
# the types of the arguments.
|
|
# the types of the arguments.
|
|
-cover open open[door Door key Item]
|
|
|
|
|
|
+cover open openDoor[door Door key Item]
|
|
|
|
|
|
# Variables are not part of the language but there are builtin commands
|
|
# Variables are not part of the language but there are builtin commands
|
|
# to define them. Variables are set in the current scope with
|
|
# to define them. Variables are set in the current scope with
|
|
@@ -167,26 +179,32 @@ if (less a 10) {
|
|
$foo
|
|
$foo
|
|
#
|
|
#
|
|
|
|
|
|
|
|
+# There are built in functions for getting, setting and invoking the fields
|
|
|
|
+# of object valued types:
|
|
|
|
+of $door1 name # "red door"
|
|
|
|
+make $door1 name "green door"
|
|
|
|
+invoke $door1 open $key
|
|
|
|
+
|
|
|
|
+# Since these three are common, there is syntax available to
|
|
|
|
+# abbreviate this, using ' or 's or , and ; :
|
|
|
|
+door1's name # same as (of $door1 name)
|
|
|
|
+door1's name "green door" # same as (make $door1 name "green door")
|
|
|
|
+door1, open $key1 # same as invoke $door1 open $key1, open must be a
|
|
|
|
+# callable method
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# It is possible to define keywords. These get replaced by a single token.
|
|
|
|
+# This allows to have an English-like or other natural language-like syntax.
|
|
|
|
+# For example, openDoor above can also be defined as follows:
|
|
|
|
+to openDoor list door Door key Item done Bool do
|
|
|
|
+ if as contains as of a door key so a key so do
|
|
|
|
+ make a door open true
|
|
|
|
+ end
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+
|
|
# That's all there is to the syntax. Apart from the built in commands,
|
|
# That's all there is to the syntax. Apart from the built in commands,
|
|
# the semantics are up to you to implement as
|
|
# the semantics are up to you to implement as
|
|
-# embedded commands, or by redirecting the command output and input.
|
|
|
|
|
|
+# embedded commands or operators.
|
|
# Do note that MUESLI uses dynamic scoping for ease of implementation
|
|
# Do note that MUESLI uses dynamic scoping for ease of implementation
|
|
|
|
|
|
-#{
|
|
|
|
-
|
|
|
|
-BLOCK
|
|
|
|
-PUSHS "More"
|
|
|
|
-CALL print
|
|
|
|
-PUSHBLOCK
|
|
|
|
-PUSHW else
|
|
|
|
-BLOCK
|
|
|
|
-PUSHS "Less"
|
|
|
|
-CALL print
|
|
|
|
-PUSHBLOCK
|
|
|
|
-PUSHI 10
|
|
|
|
-PUSHW a
|
|
|
|
-CALL less
|
|
|
|
-CALL if
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|