all repos — min @ 1a59e1ca38cb85f90117996bb530e5abf8b63e54

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
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
@test
#test

"lang" describe

  (symbols size 163 ==) 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

  (defmod mymath inspect ("myplus") ==) 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

  (
   (
    (() 1 at) 
    (first) 
    ("Caught an " swap concat)
    ) try "Caught an IndexError" ==) assert 

  (
   (
    (("TestError" "Test Message") raise) 
    (1 at)
    ) try "Test Message" ==) assert

  (
   ((dup 0 ==) (1 +) (dup 1 -) ( * ) linrec) :factorial
   (
    (8 factorial)
    (12 factorial)
    (9 factorial)
    ) counquote (40320 479001600 362880) ==) assert

  report
  ; Tidy up
  ~defmod
  clear