all repos — min @ 28a40c6da8e06b607d2b72031763d3ea0393e06a

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
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
'test load
'test import

newline 
symbols size :total-symbols
sigils size :total-sigils
"Total Symbols: $1" (total-symbols) => % puts! 
"Total Sigils: $1" (total-sigils) => % puts!
newline 

"lang" describe

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

  (symbols "a" in? false ==) assert
  
  5 :five
  (symbols "five" in?) assert

  (
    ((1 2 3 4 5 6)) :test-data

    (
      :item
      "_$1" (item) => % :namesym
      (item dup *) namesym define
      namesym ROOT publish
    ) :def

    test-data (def) foreach

    _2 _5 _1 + +
    30 ==
  ) assert
  
  
  ~five
  (symbols "five" in? false  ==) assert

  (
    (+) :myplus
  ) +mymath

  (symbols "mymath" in?) assert
  
  ('mymath import symbols "myplus" in?) assert

  ('mymath import 2 3 myplus 5 ==) assert

  (2 3 mymath ^myplus 5 ==) assert

  ; Extend an existing scope
  ;(
  ;  ('mymath import 
  ;   (-) :myminus
  ;  ) @mymath 5 2 mymath ^myminus 3 ==) assert
  ; 
  ;(mymath inspect ("myminus" "myplus") ==) assert

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

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

  (2 2 mymath ^myplus 4 ==) assert
  

  (2 quote (2) ==) assert

  ((2 3) unquote stack (2 3) ==) assert

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

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

  ("NO" (2 3 >) ("YES") when "NO" ==) assert

  ((2 3 <) ("YES") when "YES" ==) assert

  ((2 3 >) ("YES") unless "YES" ==) assert


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

  (
   (
    (pop) 
    ('error dget) 
    ("finally")
    ) try stack ("MinEmptyStackError" "finally") ==) assert 

  ("aaaa" :cd cd "aaaa" ==) assert ;It is possible to shadow sealed symbols in child scopes

  (((2 :a1 'a1 seal 3 :a1) ("failed")) try "failed" ==) assert

  (
    1 :a1
    'a1 seal
    'a1 unseal
    2 :a1
    2 a1 ==) assert

  (
   (
    (((error "TestError")(message "Test Message")) raise) 
    ('error dget)
    ) try "TestError" ==) assert

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

  (
   (
    (() 1 get)
    (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 "\n" "" replace " " "" replace "[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

  (((1 2 3)) :sym1 >sym1 stored-symbols "sym1" in?) assert

  (<sym1 symbols "sym1" in?) assert

  ('sym1 remove-symbol stored-symbols "sym1" in? false ==) assert

  (0 :temp (1 2 3) (temp + @temp) foreach 6 temp ==) assert

  ((1 +) :mysucc 'mysucc source (1 +) ==) assert

  (6 
    (
      ((3 ==) (false))
      ((3 <) (false))
      ((3 >) (true))
    ) case
  ) assert

  (time module-symbols ("datetime" "now" "tformat" "timeinfo" "timestamp") ==) assert

  (sys module-sigils ("!" "$" "&") ==) assert

  report
  ; Tidy up
  newstack