JanetDocsSign in with Github

JanetDocs is a community documentation site for the Janet programming language

Loading...

Recent examples

(put-in  @{:a @{:aa 5} :b @{:bb 6}}  [:c]          9)  # => @{:a @{:aa 5} :b @{:bb 6} :c 9}
(put-in  @{:a @{:aa 5} :b @{:bb 6}}  [:a :aa]      9)  # => @{:a @{:aa 9} :b @{:bb 6}}
(put-in  @{:a @{:aa 5} :b @{:bb 6}}  [:a :cc :ddd] 9)  # => @{:a @{:cc @{:ddd 9} :aa 5} :b @{:bb 6}}

(put-in  @[:a :b @[:aa :bb :cc]]  [2 1] :zz )  # => @[:a :b @[:aa :zz :cc]]
(put-in  @[:a :b @[:aa :bb :cc]]  [5]   :z  )  # => @[:a :b @[:aa :bb :cc] nil nil :z]

(put-in  @[:a :b @[:aa :bb :cc]]  [4 0]   :zz )  # => @[:a :b @[:aa :bb :cc] nil @{0 :zz}]
(put-in  @[:a :b @[:aa :bb :cc]]  [4 :yy] :zz )  # => @[:a :b @[:aa :bb :cc] nil @{:yy :zz}]

put-incellularmitosis
(put  @{:a 4 :b 5}  :c 6         )  # => @{:a 4 :b 5 :c 6}
(put  @{:a 4 :b 5}  :b nil       )  # => @{:a 4}
(put  @{:a 4 :b 5}  :z nil       )  # => @{:a 4 :b 5}

(put  @[:a :b :c]   0  :z        )  # => @[:z :b :c]
(put  @[:a :b :c]   1  nil       )  # => @[:a nil :c]

(put  @[:a :b :c]   5  :d        )  # => @[:a :b :c nil nil :d]

(put  @"hello"      0  "z"       )  # error: can only put integers in buffers
(defn ord [ch] (first (string/bytes ch)))
(ord "z")  # => 122
(put  @"hello"      0  122       )  # => @"zello"
(put  @"hello"      0  (ord "z") )  # => @"zello"
(put  @"hello"      8  (ord "y") )  # => @"hello\0\0\0y"
putcellularmitosis
(next  [4 5 6]    )  # => 0
(next  [4 5 6]  0 )  # => 1
(next  [4 5 6]  1 )  # => 2
(next  [4 5 6]  2 )  # => nil

# note that dictionary keys are not necessarily in the same order
# as the corresponding literal.
(next  {:a 5 :b 6 :c 7}     )  # => :a
(next  {:a 5 :b 6 :c 7}  :a )  # => :c
(next  {:a 5 :b 6 :c 7}  :c )  # => :b
(next  {:a 5 :b 6 :c 7}  :b )  # => nil
nextcellularmitosis
(or true)        # => true
(or true true)   # => true
(or true false)  # => true

(or false 1 2)  # => 1
(or false 2 1)  # => 2

(or false nil)  # => nil
(or nil false)  # => false

# note that `or` does not behave as you might expect
# when used with `apply` and `splice`:
(or 1 2 3)             # => 1
(or (splice [1 2 3]))  # => (1 2 3)
(apply or [1 2 3])     # => (if 1 1 (if 2 2 3))
orcellularmitosis
(map false? [ false nil   true  0     1     42    'a    :a    "a"   [97]  {:a 42} (fn []) ])
# =>       @[ true  false false false false false false false false false false   false   ]
false?cellularmitosis
(map true? [ true nil   false 0     1     42    'a    :a    "a"   [97]  {:a 42} (fn []) ])
# =>      @[ true false false false false false false false false false false   false   ]
true?cellularmitosis
(map bytes?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  true  true   true   false    false     false        false         ]

(map symbol?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  false false  false  false    false     false        false         ]

(map keyword?    [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false true  false  false  false    false     false        false         ]

(map string?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false true   false  false    false     false        false         ]

(map buffer?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  true   false    false     false        false         ]
string?cellularmitosis
(map bytes?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  true  true   true   false    false     false        false         ]

(map symbol?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  false false  false  false    false     false        false         ]

(map keyword?    [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false true  false  false  false    false     false        false         ]

(map string?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false true   false  false    false     false        false         ]

(map buffer?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  true   false    false     false        false         ]
keyword?cellularmitosis
(map bytes?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  true  true   true   false    false     false        false         ]

(map symbol?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  false false  false  false    false     false        false         ]

(map keyword?    [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false true  false  false  false    false     false        false         ]

(map string?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false true   false  false    false     false        false         ]

(map buffer?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  true   false    false     false        false         ]
symbol?cellularmitosis
(map  |($ {:a 7 :b 8} )   [  keys      values    kvs             pairs                 ])
# =>                     @[  @[:a :b]  @[7 8]    @[:a 7 :b 8]    @[(:a 7) (:b 8)]      ]

(map  |($ [4 5 6] )       [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1 2]  @[4 5 6]  @[0 4 1 5 2 6]  @[(0 4) (1 5) (2 6)]  ]

(map  |($ 'ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ :ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ "ab" )          [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]
pairscellularmitosis
(map  |($ {:a 7 :b 8} )   [  keys      values    kvs             pairs                 ])
# =>                     @[  @[:a :b]  @[7 8]    @[:a 7 :b 8]    @[(:a 7) (:b 8)]      ]

(map  |($ [4 5 6] )       [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1 2]  @[4 5 6]  @[0 4 1 5 2 6]  @[(0 4) (1 5) (2 6)]  ]

(map  |($ 'ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ :ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ "ab" )          [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]
kvscellularmitosis
(map  |($ {:a 7 :b 8} )   [  keys      values    kvs             pairs                 ])
# =>                     @[  @[:a :b]  @[7 8]    @[:a 7 :b 8]    @[(:a 7) (:b 8)]      ]

(map  |($ [4 5 6] )       [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1 2]  @[4 5 6]  @[0 4 1 5 2 6]  @[(0 4) (1 5) (2 6)]  ]

(map  |($ 'ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ :ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ "ab" )          [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]
valuescellularmitosis
(map  |($ {:a 7 :b 8} )   [  keys      values    kvs             pairs                 ])
# =>                     @[  @[:a :b]  @[7 8]    @[:a 7 :b 8]    @[(:a 7) (:b 8)]      ]

(map  |($ [4 5 6] )       [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1 2]  @[4 5 6]  @[0 4 1 5 2 6]  @[(0 4) (1 5) (2 6)]  ]

(map  |($ 'ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ :ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ "ab" )          [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]
keyscellularmitosis
(get-in  {:a {:cc 2} :b {:dd 3}}  [:a]     42)  # => {:cc 2}
(get-in  {:a {:cc 2} :b {:dd 3}}  [:a :cc] 42)  # => 2

(get-in  {:a {:cc 2} :b {:dd 3}}  [0]  42)  # => 42
(get-in  {:a {:cc 2} :b {:dd 3}}  [:z] 42)  # => 42
get-incellularmitosis
(get-in  [[4 5] [6 7]]  [0]    42)  # => (4 5)
(get-in  [[4 5] [6 7]]  [0 1]  42)  # => 5

(get-in  [[4 5] [6 7]]  [-1]     42)  # => 42
(get-in  [[4 5] [6 7]]  [9 9 9]  42)  # => 42
get-incellularmitosis
(get      [4 5 6]   -1     )  # => nil
(in       [4 5 6]   -1  42 )  # error
(get-in   [4 5 6]  [-1] 42 )  # => 42

(get     {:a 1}   -1     )  # => nil
(in      {:a 1}   -1  42 )  # => 42
(get-in  {:a 1}  [-1] 42 )  # => 42

getcellularmitosis
(get      [4 5 6]   -1     )  # => nil
(in       [4 5 6]   -1  42 )  # error
(get-in   [4 5 6]  [-1] 42 )  # => 42

(get     {:a 1}   -1     )  # => nil
(in      {:a 1}   -1  42 )  # => 42
(get-in  {:a 1}  [-1] 42 )  # => 42
incellularmitosis
(in  [10 11 12 13]  0   42 )  # => 10
(in  {:a 10 :b 20}  :a  42 )  # => 10

(in  [10 11 12]  99 42 )  # error
(in  [10 11 12]  -1 42 )  # error
(in  [10 11 12]  -2 42 )  # error
(in  {:a 1}      :z 42 )  # => 42

(map  (fn [x] (in x 0 42))   [  'a  :a  "a"  [97]  @[97]  {0 97}  @{0 97}  {:a 1} ])
# =>                        @[  97  97  97   97    97     97      97       42     ]
incellularmitosis
(get  [10 11 12 13]  0  )  # => 10
(get  {:a 10 :b 20}  :a )  # => 10

(get  [10 11 12]  99  )  # => nil
(get  [10 11 12]  -1  )  # => nil
(get  [10 11 12]  -2  )  # => nil
(get  {:a 1}      :z  )  # => nil

(map  (fn [x] (get x 0))   [  'a  :a  "a"  [97]  @[97]  {0 97}  @{0 97}  ])
# =>                      @[  97  97  97   97    97     97      97       ]
getcellularmitosis
(map length  [  'a  :a  "a"  [97]  @[97]  {0 97}  @{0 97}  ])
# =>        @[  1   1   1    1     1      1       1        ]
lengthcellularmitosis
(int/u64 42)    # => <core/u64 42>
(int/u64 42.1)  # => <core/u64 42>
(int/u64 "42")  # => <core/u64 42>
int/u64cellularmitosis
(int/s64 42)    # => <core/s64 42>
(int/s64 42.1)  # => <core/s64 42>
(int/s64 "42")  # => <core/s64 42>
int/s64cellularmitosis
(abstract? (file/temp))  # => true
(abstract? (int/s64 1))  # => true

(map abstract?  [ nil true 97 'a :a "a" ])
# => @[false false false false false false]

(map abstract?  [ [97]  @[97]  {0 97}  @{0 97} ])
# => @[false false false false]

(map abstract?  [ even? loop file/open  (fn [])  ])
# => @[false false false false]

(map abstract?  [ (file/temp)  (fiber/new (fn []))  ])
# => @[true false]
abstract?cellularmitosis
(map idempotent?  [ nil  true 97   'a   :a   "a"  ])
# =>             @[ true true true true true true ]

(map idempotent?  [  [97]   @[97]  {0 97}  @{0 97}  ])
# =>             @[  false  false  false   false    ]

(map idempotent?  [  (fn [])  even?  loop  file/open  ])
# =>             @[  true     true   true  true       ]

(map idempotent?  [  (file/temp)  (fiber/new (fn []))  ])
# =>             @[  true         true                 ]
idempotent?cellularmitosis
(map dictionary? [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     true         true          ]

(map struct?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     true         false         ]

(map table?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     false        true          ]
dictionary?cellularmitosis
(map indexed?    [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  true     true      false        false         ]

(map tuple?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  true     false     false        false         ]

(map array?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    true      false        false         ]
indexed?cellularmitosis
(map bytes?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  true  true   true   false    false     false        false         ]

(map symbol?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ true  false false  false  false    false     false        false         ]

(map keyword?    [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false true  false  false  false    false     false        false         ]

(map string?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false true   false  false    false     false        false         ]

(map buffer?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  true   false    false     false        false         ]
bytes?cellularmitosis
(map dictionary? [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     true         true          ]

(map struct?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     true         false         ]

(map table?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     false        true          ]
table?cellularmitosis
(map dictionary? [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     true         true          ]

(map struct?     [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     true         false         ]

(map table?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    false     false        true          ]
struct?cellularmitosis
(map indexed?    [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  true     true      false        false         ]

(map tuple?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  true     false     false        false         ]

(map array?      [ 'ab   :ab   "ab"   @"ab"  [97 98]  @[97 98]  {0 97 1 98}  @{0 97 1 98}  ])
# =>            @[ false false false  false  false    true      false        false         ]
tuple?cellularmitosis