JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

Community documentation for Janet

Supported Modules

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

Loading...

Random Examples

(keyword "")
# => :
keywordsogaiuPlayground
(forever 
 (print "and then?") 
 (ev/sleep 1) 
 (print "no and then!")) 

# => and then? 
# sleeps for one second
# => no and then!
# => and then?
# sleeps for one second
# => no and then!
# ...
foreverjgartePlayground
(let [a 1]
 (let [b a]
  b)) # => 1
letjgartePlayground
(math/atan 1)    # 0.785398
(math/atan 0.5)  # 0.463648
math/atanbtbytesPlayground
(+ 1 2 3)      # => 6
(sum [1 2 3])  # => 6
sumcellularmitosisPlayground
(filter (fn [x] (> x 2)) [1 2 3 4 5])  # @[3 4 5]
filterbtbytesPlayground
# In Linux, "everything is a file" so:

(def pid (os/getpid)) 

pid
# =>
367537

(def statm-path (string "/proc/" pid "/statm"))

statm-path
# =>
"/proc/367537/statm"

(slurp statm-path)
# =>
@"1380 971 683 82 0 362 0\n"
slurpsogaiuPlayground
(reduce (fn [s1 s2]
          (string "[" s1 "+" s2 "]"))
        "x"
        ["a" "b" "c"])

#=> "[[[x+a]+b]+c]"
reduceuvtcPlayground
(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?cellularmitosisPlayground
# based on: https://codeberg.org/veqq/janetdocs/src/commit/54a964d1a35920af2655c4932a9b51379e8b9380/seed.janet#L16 

(def core-api (all-bindings))
(def alldocs @[])

(loop [b :in core-api]
  (when (not= "allbindings" (string b))
    (do
      (def buf @"")
      (with-dyns [:out buf]
        (doc* b)
        (array/push alldocs {:name (string b) :docstring (string buf)})))))

(pp alldocs)
with-dynsveqqqPlayground
(partition-by even? [1 1 2 3 5 8 13 21])
# => @[@[1 1] @[2] @[3 5] @[8] @[13 21]]
partition-bysogaiuPlayground
(defn dataframe 
  ``Create an empty dataframe with the given columns``
  [& columns]
  (tabseq [c :in columns] c @[]))
tabseqveqqqPlayground
# with by function 

(sorted [1 -2 2 3 9 -10] >)  #@[9 3 2 1 -2 -10]
sortedleobmPlayground
(def a @[23 42])
(array/clear a)
(pp a)
# => prints @[]
array/clearpepePlayground
(<= 1 2 3) # => true
(<= 1 2 1) # => false
<=pepePlayground