2011-06-14 20:29:13 +03:00
|
|
|
VERM
|
|
|
|
; standard verm file, global engine things should be put here
|
|
|
|
|
|
|
|
!?PI;
|
2011-06-18 21:24:56 +03:00
|
|
|
; example 1 --- Hello World
|
2011-06-14 20:29:13 +03:00
|
|
|
![print ^Hello world!^]
|
2011-06-18 21:24:56 +03:00
|
|
|
|
|
|
|
; example 2 --- simple arithmetics
|
2011-06-14 20:29:13 +03:00
|
|
|
![defun add [x y] [+ x y]]
|
|
|
|
![print [add 2 3]]
|
2011-06-18 21:24:56 +03:00
|
|
|
|
|
|
|
; example 3 --- semantic macros
|
|
|
|
![defmacro do-n-times [times body]
|
|
|
|
`[progn
|
|
|
|
[setq do-counter 0]
|
|
|
|
[setq do-max ,times]
|
|
|
|
[do [< do-counter do-max]
|
|
|
|
[progn
|
|
|
|
[setq do-counter [+ do-counter 1]]
|
|
|
|
,body
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
![do-n-times 4 [print ^tekst\n^]]
|
|
|
|
|
|
|
|
|
|
|
|
; example 4 --- conditional expression
|
|
|
|
![if [> 2 1] [print ^Wieksze^] [print ^Mniejsze^]]
|
|
|
|
|
|
|
|
; example 5 --- lambda expressions
|
2011-06-14 20:29:13 +03:00
|
|
|
![[lambda [x y] [if [> x y] [print ^wieksze^] [print ^mniejsze^]]] 2 3]
|
2011-06-18 21:24:56 +03:00
|
|
|
|
|
|
|
; example 6 --- resursion
|
|
|
|
![defun factorial [n]
|
|
|
|
[if [= n 0] 1
|
|
|
|
[* n [factorial [- n 1]]]
|
|
|
|
]
|
|
|
|
]
|
2011-06-21 03:00:49 +03:00
|
|
|
![print [factorial 8]]
|