all repos — min @ 254a83cfaa4af6f704dee4db7d74ed1b3dff7088

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
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
@test
#test


"lang" describe

  "Total Symbols: " print! symbols size put!
  "  Total Sigils: " print! sigils size put!

  (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 get-stack (1 2 3 4) ==) assert

  ((1 2 3) set-stack get-stack (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 get-stack (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

  (
   (
    (pop) 
    (first) 
    ("Caught a " swap concat)
    ) try "Caught a MinEmptyStackError" ==) assert 

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

  (
   (("test" (1 2) :)) try get-stack ("test" (1 2)) ==) assert

  (
   (
    (() 1 at)
    (1)
    ) try 1 ==) assert

  ((a b +) (4 :a 5 :b) with 9 ==) assert

  ("{\"a\": 1, \"b\": 2.3}" from-json ((a 1) (b 2.3)) ==) assert

  ((1 2 3 "aaa" 'q q true) to-json "[1,2,3,\"aaa\",\";sym:'q\",\";sym:q\",true]"  ==) assert

  ((1 2 3 "aaa" 'q q true) to-json from-json (1 2 3 "aaa" 'q q true)  ==) assert

  (((a 1)(b 2)(c 3)) dictionary?) assert

  (((a 1)(b 2)(c 3)) 'b dget 2 ==) assert

  (((a 1)(b 2)(c 3)) 'b  5 dset ((a 1)(b 5)(c 3)) ==) assert

  (((a 1)(b 2)(c 3)) 'b ddel ((a 1)(c 3)) ==) assert

  (((a 1)(b 2)(c 3)) keys (a b c) ==) assert

  (((a 1)(b 2)(c 3)) values (1 2 3) ==) assert

  report
  ; Tidy up
  ~defmod
  clear