JanetDocsPlaygroundI'm feeling luckyGitHub sign in

defn



    macro
    boot.janet on line 10, column 1

    (defn name & more)

    Define a function. Equivalent to `(def name (fn name [args] ...))`.


See also:defn-1 exampleSign in to add an example
Loading...
## Quadratic Formula

(defn qform
  "Use the quadratic formula to solve for x. Returns all real solutions."
  [a b c]
  (def det (- (* b b) (* 4 a c)))
  (def factor (/ 0.5 a))
  (cond
    (neg? det) []
    (zero? det) [(* factor (- b))]
    (let [root-det (math/sqrt det)]
        [(* factor (- (- b) root-det)) (* factor (+ (- b) root-det))])))

    (qform 1 4 3) # -> (-3 -1)
bakpakinPlayground