Dak is a programming language created in 2022 by Naitik Shah.
#1291on PLDB | 2Years Old |
git clone https://github.com/daaku/dak
Dak is a Lisp like language that transpiles to JavaScript.
; Functions are varied and colorful.
; Simple function:
(fn add [a b]
(+ a b))
(prn (add 40 1))
; Async function:
(fn@ add-promises [a b]
(+ @a @b))
(prn @(add-promises (Promise.resolve 40) (Promise.resolve 2)))
; Generator function:
(fn* powers [n count]
(let [current 1]
(for [i 0 count]
(yield (*= current n)))))
(for-of [v (powers 2 5)]
(prn v))
; Async generator function:
(fn@* foo [a b]
(yield (inc @a))
(yield (inc @b)))
(for@ [v (foo (Promise.resolve 41) (Promise.resolve -43))]
(prn v))
; Exported function:
(fn ^:export plus [a b]
(+ a b))
; Exported default function:
(fn ^:export ^:default [a b]
(- a b))
; Declaration syntax:
(fn ^:decl TheClass [a]
(set this.answer a))
(prn (TheClass. 42))
; Explicit return is available:
(fn until [a]
(while true
(if (= (++ a) 42)
(return :boom))))
(prn :returned (until 40))
; Yield & Yield* are available:
(fn* it [a]
(yield (++ a))
(yield* [(++ a) (++ a)]))
(for-of [v (it 39)]
(prn "it:" v))