Skip to main content Svelte Highlight v7.21.1

Fennel language preview

1. A function and a loop

fn, local, each, and Lua built-ins
horizon-dark
;; sum two numbers
(fn add [a b]
  (+ a b))

(local greeting :hello)
(each [i v (ipairs [1 2 3])]
  (print i v))

(print (add 1 2) greeting "done")
atom-one-dark
;; sum two numbers
(fn add [a b]
  (+ a b))

(local greeting :hello)
(each [i v (ipairs [1 2 3])]
  (print i v))

(print (add 1 2) greeting "done")
github-dark
;; sum two numbers
(fn add [a b]
  (+ a b))

(local greeting :hello)
(each [i v (ipairs [1 2 3])]
  (print i v))

(print (add 1 2) greeting "done")
dracula
;; sum two numbers
(fn add [a b]
  (+ a b))

(local greeting :hello)
(each [i v (ipairs [1 2 3])]
  (print i v))

(print (add 1 2) greeting "done")
nord
;; sum two numbers
(fn add [a b]
  (+ a b))

(local greeting :hello)
(each [i v (ipairs [1 2 3])]
  (print i v))

(print (add 1 2) greeting "done")
github
;; sum two numbers
(fn add [a b]
  (+ a b))

(local greeting :hello)
(each [i v (ipairs [1 2 3])]
  (print i v))

(print (add 1 2) greeting "done")

2. Tables and iteration

a table literal, keyword keys, and icollect
horizon-dark
(local person {:name "Ada" :age 30})

(icollect [_ v (pairs person)]
  (tostring v))

(print person.name)
atom-one-dark
(local person {:name "Ada" :age 30})

(icollect [_ v (pairs person)]
  (tostring v))

(print person.name)
github-dark
(local person {:name "Ada" :age 30})

(icollect [_ v (pairs person)]
  (tostring v))

(print person.name)
dracula
(local person {:name "Ada" :age 30})

(icollect [_ v (pairs person)]
  (tostring v))

(print person.name)
nord
(local person {:name "Ada" :age 30})

(icollect [_ v (pairs person)]
  (tostring v))

(print person.name)
github
(local person {:name "Ada" :age 30})

(icollect [_ v (pairs person)]
  (tostring v))

(print person.name)

3. Conditionals and match

when, match, and accumulate
horizon-dark
(fn classify [n]
  (match n
    0 :zero
    _ (if (> n 0) :positive :negative)))

(accumulate [total 0
             _ n (ipairs [1 2 3])]
  (+ total n))
atom-one-dark
(fn classify [n]
  (match n
    0 :zero
    _ (if (> n 0) :positive :negative)))

(accumulate [total 0
             _ n (ipairs [1 2 3])]
  (+ total n))
github-dark
(fn classify [n]
  (match n
    0 :zero
    _ (if (> n 0) :positive :negative)))

(accumulate [total 0
             _ n (ipairs [1 2 3])]
  (+ total n))
dracula
(fn classify [n]
  (match n
    0 :zero
    _ (if (> n 0) :positive :negative)))

(accumulate [total 0
             _ n (ipairs [1 2 3])]
  (+ total n))
nord
(fn classify [n]
  (match n
    0 :zero
    _ (if (> n 0) :positive :negative)))

(accumulate [total 0
             _ n (ipairs [1 2 3])]
  (+ total n))
github
(fn classify [n]
  (match n
    0 :zero
    _ (if (> n 0) :positive :negative)))

(accumulate [total 0
             _ n (ipairs [1 2 3])]
  (+ total n))