OML programming constructions

Submitted by Phaul on Wed, 2006-07-19 07:02.
::

OML is the scripting language of OpenMONI. You can display whatever you want in OpenMONI window using OML. You can even write small programs in OML as well. The language is based on the Lisp language, altough it has many differences.

Comment

You can write comments into the code starting with `;'. End of line indicates the end of comment.

(here-comes-some-code) ; and this is a comment
; this is a comment too.

progn

In OML every expression has a value and sequence is not an exception: its value equals to the value of its last expression. You can write command sequences like this:

(progn
   cmd1
   cmd2
   cmd3
   ...
)

For example :

(progn
    (print 1)                          ; this prints :
    (print " swallow doesn't make a")   ; 1 swallow doesn't make a Summer.
    (print " Summer\n")                 ; note that print prints to stdout.
)                                       ; the progn's value equals to (print " Summer\n")

if

Any expression considered to be TRUE if and only if it is not evaluated to be nil. Conditional expressions (if) have 2 or 3 arguments. First argument is the condition. If it is not nil the second argument is evaluated, if it is - and there is a third argument - the third argument is evaluated. The value of the `if' is a bit complicated. It is the value of the second argument if the condition is not nil, and it is the value of the third if the condition is nil - unless there is no third argument. In that case the value of `if' is nil.

(if (isMonday) 
    (print "Today is Monday.\n")
)

; this example comes from the official date.oml
; wdtoa = week day to ascii
; in this example the next if is always the third argumwent of the previous one.
(func wdaytoa (d)
     (if (= d 0) "Sun"
     (if (= d 1) "Mon"
     (if (= d 2) "Tue"
     (if (= d 3) "Wed"
     (if (= d 4) "Thu"
     (if (= d 5) "Fri"
     (if (= d 6) "Sat"
     "???"
     )))))))
); func wdaytoa

while

You can write loops with `while'. The first argument is the condition, it is evaluated at the begining of every turn, than if it's not nil the remaining arguments become evaluated and the next turn begins. The value of the while is nil if the condition is nil at the first time, otherwise the value of the while's last argument at the last turn.

(set i 0)                    ; set i to 0
(while (< i 5)               ; while i is less than 5
     (set i (+ i 1))         ; increase i by 1
)                            ; value of the `while' is obviously 5
                             ; (the value of the last `set')