Calico Sympl

From IPRE Wiki
Jump to: navigation, search

Sympl is a sample language provided from Microsoft to show the development of a DLR language. A implementation of the Sympl language is also provided written in Python, so this makes a very easy example to explore. We provide it in Calico as an extended example of the DLR, and how to connect such a language into Calico.

For more details on the implementation of Sympl, please see

Sympl is a simple version of Lisp. Many of the below examples come from the Sympl documentation.

(+ 3 5)
(+ (* 10 x) (/ y 2))
(< x max-fixnum)
(or arg default-value)
(= (not (and a b))
   (or (not a) (not b)))


In the below syntax description, the square brackets indicate optional components. Plus indicates 1 or more expressions.

(loop expr+)
(break [expr])

Break expressions do not return. They transfer control to the end of the loop. Break exits the loop and produces a value for the loop if it has an argument. Otherwise, the loop returns nil.

Not yet implemented:

(for ([id init-expr [step-expr]]) ;;while is (for () (test) ...)
     (test-expr [result-expr])

(foreach (id seq-expr [result-expr]) expr*)

(try <expr>
  [(catch (<var> <type>) <body>)] *
  [(finally <body>)] )

Sympl uses the defun keyword form to define functions. It takes a symbol as the first argument and a list of parameter names as the second.

(defun name (param1 param2) (do-stuff param1) param2)
(set x 5)
(set (elt arr 0) "bill") 
(set 3)

Binary arithmetic: +, -, *, /

(* (+ x 5) (- y z))

Boolean: and, or, not.

Comparisons: =, !=, <, >, eq.

Indexing: elt

(elt "bill" 2)
(elt '(a b c) 1)
(elt dot-net-dictionary "key")

Object instantiation: new

(new system.text.stringbuilder "hello world!")
(set types (system.array.createinstance system.type 1))
(set (elt types 0) system.int32)
(new (system.collections.generic.list`1.MakeGenericType types))

Object member access: uses infix dot/period syntax
(set o.blah 5)


Importing CLR modules:

(import system)
(system.console.writeline "hey")
(imports lists)
(lists.append '(a b c) '(1 2 3))

Local variables:

(let* ((var1 init1)
       (var2 init2))
   e1 e2 e3)

Standard list operations:

>>> (cons 'a (cons 'b nil)) 
--> (a b)

>>> (cons 'b 'c)) 
--> (a b . c)

>>> (list 'a 'b 3 "c") 
--> (a b 3 "c")

>>> (list 2 '(b c) 3)) 
--> (a 2 (b c) 3)

Using CLR from Sympl:

(set x (new System.Text.StringBuilder "hello"))
(set y (new (x.GetType) (x.ToString)))
(System.Array.CreateInstance System.String 3)
( (lambda (e) e.Name))
( arg1 arg2) ;; two InvokeMembers

;;; Create List<int>
(set types (system.array.CreateInstance system.type 1))
(set (elt types 0) System.Int32)
(new (system.collections.generic.list`1.MakeGenericType types)))
;;; Create a Dictionary<string,int>
(set types (system.array.CreateInstance system.type 2))
(set (elt types 0) system.string)
(set (elt types 1) system.int32)
(new (system.collections.generic.dictionary`2.MakeGenericType

(new (generic-type system.collections.generic.list system.int32))

(set l (new (System.Collections.Generic.List`1.MakeGenericType