std.verm 824 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. VERM
  2. ; standard verm file, global engine things should be put here
  3. !?PI;
  4. ; example 1 --- Hello World
  5. ![print ^Hello world!^]
  6. ; example 2 --- simple arithmetics
  7. ![defun add [x y] [+ x y]]
  8. ![print [add 2 3]]
  9. ; example 3 --- semantic macros
  10. ![defmacro do-n-times [times body]
  11. `[progn
  12. [setq do-counter 0]
  13. [setq do-max ,times]
  14. [do [< do-counter do-max]
  15. [progn
  16. [setq do-counter [+ do-counter 1]]
  17. ,body
  18. ]
  19. ]
  20. ]
  21. ]
  22. ![do-n-times 4 [print ^tekst\n^]]
  23. ; example 4 --- conditional expression
  24. ![if [> 2 1] [print ^Wieksze^] [print ^Mniejsze^]]
  25. ; example 5 --- lambda expressions
  26. ![[lambda [x y] [if [> x y] [print ^wieksze^] [print ^mniejsze^]]] 2 3]
  27. ; example 6 --- resursion
  28. ![defun factorial [n]
  29. [if [= n 0] 1
  30. [* n [factorial [- n 1]]]
  31. ]
  32. ]
  33. ![print [factorial 8]]