all repos — min @ 971cdb5d8daddbb43132df2142cf90f06e83f0a4

A small but practical concatenative programming language.

tests/lang.min

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
@test
#test

"lang" describe

  (symbols size 159 ==) assert

  (sigils size 10 ==) assert

  (debug? false ==) assert

  (2 'a define
    (3 a + (5 'a define a) -> +) -> a + 12 ==) assert

  (symbols "a" contains false ==) assert
  
  5 :five
  (symbols "five" contains) assert
  
  ~five
  (symbols "five" contains false  ==) assert

  (
    (
      (+) :myplus
    ) => :mymath
  ) :defmod
  
  (defmod symbols "mymath" contains) assert

  (defmod #mymath 2 3 myplus 5 ==) assert

  ; Extend an existing scope
  (defmod 
    (#mymath 
     (-) :myminus) => .mymath 
    5 2 %mymath:myminus 3 ==) assert

  ((":mysigil" concat) ', sigil ,test "test:mysigil" ==) assert

  ("3 4 +" eval 7 ==) assert

  ("2 2 +" "tests/testload.min" fwrite @testload 4 ==) assert
  "tests/testload.min" rm

  (defmod 2 2 %mymath:myplus 4 ==) assert
  
  (1 2 3 4 getstack (1 2 3 4) ==) assert

  ((1 2 3) setstack getstack (1 2 3) ==) assert

  ((1 2) (3 4) concat (1 2 3 4) ==) assert

  ((1 2 3) first 1 ==) assert
  
  ((1 2 3) rest (2 3) ==) assert

  (2 quote (2) ==) assert

  ((2 3) unquote getstack (2 3) ==) assert

  (4 (1 2 3) append (1 2 3 4) ==) assert

  (1 (2 3) cons (1 2 3) ==) assert

  ((1 2 3 4) 2 at 3 ==) assert

  ((1 2 3) size 3 ==) assert

  ((1 2 3 4) 5 contains false ==) assert
  ((1 2 3 4) 2 contains) assert

  ((1 2 3 4) (2 +) map (3 4 5 6) ==) assert

  (3 (succ) 3 times 6 ==) assert

  ((2 3 >) ("YES") ("NO") ifte "NO" ==) assert
  ((2 3 <) ("YES") ("NO") ifte "YES" ==) assert

  (0 :c
    (c 10 <) (c succ .c) while
    c 10 ==) assert

  ((1 2 3 4 5) (even?) filter (2 4) ==) assert

  (5 (dup 0 ==) (1 +) (dup 1 -) ( * ) linrec 120 ==) assert ;factorial of 5

  report
  ; Tidy up
  ~defmod
  clear