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

(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?cellularmitosisPlayground
(invert [(chr "y") (chr "o")])
# => @{111 1 121 0}
invertsogaiuPlayground
(def h ["a" "b" :c]) # => ("a" "b" :c)

(find (fn [a] (= "a" a)) h) # => "a"
findfaywongPlayground
(->  1 (< 2))   # -> true
(->> 1 (< 2))   # -> false
->cellularmitosisPlayground
(let [buf @"hello"]
  (buffer/blit buf "zany world" -1 4))
# =>
@"hello world"
buffer/blitsogaiuPlayground
(print :hi ` ` "there" @`` `` @"mate")
# => nil
printsogaiuPlayground
(ffi/context "/usr/lib64/libSDL2.so")

(ffi/defbind SDL_CreateWindow :ptr
    [title :string
     x :int
     y :int
     w :int
     h :int
     flags :uint32])

(ffi/defbind SDL_Delay :void [ms :uint32])
(ffi/defbind SDL_DestroyWindow :void [window :ptr])
(ffi/defbind SDL_Quit :void [])
(def SDL_WINDOW_SHOWN 0x00000004)

(defn main [&]
  (def window (SDL_CreateWindow "Hello world!" 0 0 640 480 SDL_WINDOW_SHOWN))
  (SDL_Delay 4000)
  (SDL_DestroyWindow window)
  (SDL_Quit))
ffi/defbindAndriamanitraPlayground
(net/address "0.0.0.0" 80) # => <core/socket-address 0x55CABA438E90>

(net/address "0.0.0.0" 8989) # => <core/socket-address 0x55CABA439980>

net/addressjgartePlayground
(os/realpath ".") # => "/home/jgarte"

(os/realpath "Downloads") # => "/home/jgarte/Downloads"
os/realpathjgartePlayground
(array/new-filled 3)     # => @[nil nil nil]
(array/new-filled 3 :a)  # => @[:a :a :a]
array/new-filledcellularmitosisPlayground
(string/find "needle"
             "hay hay hay needle hay")
# => 12
string/findsogaiuPlayground
(repeat 3 (print "HO"))
# => prints
# HO
# HO
# HO
repeatpepePlayground
(keyword "")
# => :
keywordsogaiuPlayground
(os/time)  # => 1593838384
(os/date)  # => {:month 6 :dst false :year-day 185 :seconds 8 :minutes 53 :week-day 6 :year 2020 :hours 4 :month-day 3}
(os/mktime (os/date))  # => 1593838390
os/mktimecellularmitosisPlayground
(import joy)

# given a handler
(defn handle-func [request]
  (joy/text/plain (string "Hi " ((request :params) :name))))

# joy/defroutes will prepare routes
(joy/defroutes r [:get "/hi/:name" :handle-func])
# which you can pass to joy/app
(joy/server (joy/app {:routes r}) 9002)
# visit localhost:9002/hi/bob
joy/defroutesveqqqPlayground