Janet 1.11.1-4cc6809 Documentation
(Other Versions: 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )


Janet uses the get function to retrieve values from inside data structures. In many cases, however, you do not need the get function at all. Janet supports destructuring, which means both the def and var special forms can extract values from inside structures themselves.

# Without destructuring, we might do
(def my-array @[:mary :had :a :little :lamb])
(def lamb (get my-array 4))
(print lamb) # Prints :lamb

# Now, with destructuring,
(def [_ _ _ _ lamb] my-array)
(print lamb) # Again, prints :lamb

# Destructuring works with tables as well
(def person @{:name "Bob Dylan" :age 77})
  {:name person-name
   :age person-age} person)
(print person-name) # Prints "Bob Dylan"
(print person-age)  # Prints 77

Destructuring works in many places in Janet, including let expressions, function parameters, and var. It is a useful shorthand for extracting values from data structures and is the recommended way to get values out of small structures.