Despite being a dynamically typed language, fennel has several ways to declare variables.
(let [varname (value) varname2 (value2)]
cod -2 e
)
let creates locals that can only be used within the let declaration. The variable declaractions are wrapped in a single set of square brackets, and are operated on within the function body after the square brackets.
Multiple nested declaractions can be made and operated on, and functions can be bound to variables
; this example creates a variable "pwd" that recieves the output of the shell command `pwd`
; the second let reads the output of pwd to a string
; the third let trims whitespace
(let [pwd (io.popen "pwd")]
(let [pwd (pwd:read :*a)]
(let [pwd (pwd:gsub "^%s*(.-)%s*$" "%1")] (print pwd)))))
(local pi 3.1415)
local creates a local constant that cannot be modified.
(var count 1)
(set count (+ count 1))
var creates a mutable local variable that can be used throughout the file, but cannot be