JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

Community documentation for Janet

Supported Modules

Welcome, I'm happy to see you here! Feel free to add a happy example, the more the merrier!

Loading...

Random Examples

(from-pairs [[:hello "world"] [:foo "bar"]]) 

# => @{:foo "bar" :hello "world"}
from-pairsjgartePlayground
# convert a string to an integer
(peg/match '(number :d+) "123")
#=> @[123]

(first (peg/match '(number :d+) "123"))
#=> 123
peg/matcherichaneyPlayground
# `parse` can decode arbitrary JDN (Janet Data Notation) encoded by `string/format`

(def encoded (string/format "%j" @{:a 123 :b "foo" :c @{1 [1.2 2.3 3.4]}}))
# => "@{:a 123 :b \"foo\" :c @{1 @[1.2 2.2999999999999998 3.3999999999999999]}}"

(parse encoded)
# => @{:a 123 :b "foo" :c @{1 @[1.2 2.3 3.4]}}
parseCFiggersPlayground
(os/which)  # => :macos
os/whichcellularmitosisPlayground
(from-pairs [[:a 1] [:b 2]])
# => @{:a 1 :b 2}
from-pairsswlkrPlayground
(<)        # -> true
(< 1)      # -> true
(< 1 2)    # -> true
(< 2 1)    # -> false
(< 1 2 3)  # -> true
(< 1 3 2)  # -> false
<cellularmitosisPlayground
[1 2 3]               # => (1 2 3)
(tuple/type [1 2 3])  # => :parens

(tuple/brackets 1 2 3)               # => [1 2 3]
(tuple/type (tuple/brackets 1 2 3))  # => :brackets
tuple/typecellularmitosisPlayground
(zipcoll [:a :b :c] [1 2 3])  #=> @{:c 3 :a 1 :b 2}
zipcolluvtcPlayground
(map nil? [nil  0     false []   ])
# =>     @[true false false false]
nil?cellularmitosisPlayground
(let [seed 0]
  (= (math/rng-uniform (math/rng seed))
     (math/rng-uniform (math/rng seed))))
# => true
math/rng-uniformsogaiuPlayground
math/int32-max # => 2147483647
math/int32-maxjgartePlayground
(import spork/charts :as c)
(import spork/gfx2d :as g)
(g/save "bla.png" (c/plot-line-graph
                   :canvas (g/blank 100 100)
                   :data {:timestamp [1 2 3 40 5 60]
                          :temperature-1 [75.1 75.2 75.4 75.5 75.5 75.4]
                          :temperature-2 [55.1 55.4 55.7 60.0 60.4 60.9]}
                   :x-column :timestamp
                   :y-column [:temperature-1 :temperature-2]))

# then you can look at bla.png
spork/charts/plot-line-graphveqqqPlayground
(defn return-nil [x] nil)
(-?> 1 inc)                     # -> 2
(-?> 1 inc inc)                 # -> 3
(-?> 1 inc inc return-nil)      # -> nil
(-?> 1 inc inc return-nil inc)  # -> nil
-?>cellularmitosisPlayground
(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?cellularmitosisPlayground
(partition-by even? [1 1 2 3 5 8 13 21])
# => @[@[1 1] @[2] @[3 5] @[8] @[13 21]]
partition-bysogaiuPlayground
(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?cellularmitosisPlayground
(peg/match ~{:main (capture (some :S))}
           "hello world")
# => @["hello"]
peg/matchsogaiuPlayground
(math/hypot 1 1)  # => 1.41421
(math/sqrt 2)     # => 1.41421
math/hypotcellularmitosisPlayground
(chr "a")  # => 97
chrcellularmitosisPlayground
(defn slurp-lines [path]
  (string/split "\n" (slurp path)))
string/splitcellularmitosisPlayground