(index ("doto" 0) ("->" 565) ("->*" 565) ("->>" 1407) ("->>*" 1407) ("as->" 1821) ("and->" 2327) ("if-let" 2957) ("if-let*" 3090) ("atom" 3373) ("atom?" 3486) ("atom-value" 3579) ("atom-compare-and-set!" 3691) ("atom-swap!" 4001) ("atom-reset!" 4307))
(def (sig (syntax "(doto val (proc args ...) ...)" (id doto))) (p "Inserts " (tt "val") " as the first argument of each " (tt "(proc args ...)") " clause (i.e. right after " (tt "proc") "). Returns " (tt "val") ". This is useful e.g. for mutating a record on initialization.") (p "Example:") (highlight scheme "(define boolean-vector\n  (doto (make-vector 100)\n        (vector-fill! #t 0 50)\n        (vector-fill! #f 50)))\n=>\n\n(define boolean-vector\n  (let ((vec (make-vector 100)))\n    (vector-fill! vec #t 0 50)\n    (vector-fill! vec #f 50)\n    vec))"))
(def (sig (syntax "(-> val (proc args ...) ...)" (id ->)) (syntax "(->* val (proc args ...) ...)" (id ->*))) (p "Inserts " (tt "val") " as the first argument of the first " (tt "(proc args ...)") " clause. The resulting form is then inserted as the first argument of the following " (tt "proc") " form and so on. This is known as the " (i "thrush combinator") ". The starred version (" (tt "->*") ") is multi value aware, i.e. each form's return values are spliced into the argument list of the successing form. As a shorthand it is also possible to pass " (tt "proc") " instead of " (tt "(proc)") ".") (p "Single value example:") (highlight scheme "\n(-> 10 (- 2) (/ 5) (* 3))\n\n=>\n\n(* (/ (- 10 2) 5) 3)") (p "Multi value example:") (highlight scheme "\n(->* (values 1 2) (list))\n\n=>\n\n(receive args (values 1 2) (apply list args))"))
(def (sig (syntax "(->> val (proc args ...) ...)" (id ->>)) (syntax "(->>* val (proc args ...) ...)" (id ->>*))) (p "Works just like " (tt "->") " and " (tt "->*") " only that the forms are inserted at the end of each successive clause's argument list.") (p "Example:") (highlight scheme "(->> (iota 10)\n     (map add1)\n     (fold + 0)\n     (print))\n\n=>\n\n(print\n (fold + 0\n  (map add1\n   (iota 10))))"))
(def (sig (syntax "(as-> val name forms ...)" (id as->))) (p "Evaluates " (tt "forms") " in order in a scope where " (tt "name") " is bound to " (tt "val") " for the first form, the result of that for the second form, the result of that for the third form, and so forth. Returns the result of the last form.") (p "Examples:") (highlight scheme "(as-> 3 x (+ x 7) (/ x 2)) => 5") (p "It's mainly useful in combination with " (tt "->") ":") (highlight scheme "(-> 10 (+ 3) (+ 7) (as-> x (/ 200 x))) => 10"))
(def (sig (syntax "(and-> val forms ...)" (id and->))) (p "Works just like " (tt "->") " but will return " (tt "#f") " in case " (tt "val") " or any of the " (tt "forms") " evaluates to " (tt "#f") ".") (p "Examples:") (highlight scheme "(define some-alist '((a . 1) (b . 2)))\n\n(and-> 'b (assq some-alist) cdr add1) => 3\n\n(and-> 'c (assq some-alist) cdr add1) => #f") (p "This syntax is essentially a shortcut for certain uses of " (tt "and-let*") ", e.g. the above example would often be expressed like this:") (highlight scheme "(and-let* ((x 'b)\n           (x (assq x some-alist))\n           (x (cdr x)))\n  (add1 x))"))
(def (sig (syntax "(if-let (var val) then else)" (id if-let))) (p "Equivalent to " (tt "(let ((var val)) (if var then else))") "."))
(def (sig (syntax "(if-let* ((x1 y1) (x2 y2) ...) then else)" (id if-let*))) (p "Similar to " (tt "(or (and-let* ((x1 y1) (x2 y2) ...) then) else)") " except that returning " (tt "#f") " from the " (tt "then") " clause will not lead to the " (tt "else") " clause being evaluated."))
(def (sig (procedure "(atom value)" (id atom))) (p "Returns and atom with the given initial " (tt "value") "."))
(def (sig (procedure "(atom? x)" (id atom?))) (p "Checks whether " (tt "x") " is an atom."))
(def (sig (procedure "(atom-value atom)" (id atom-value))) (p "Returns the current value of " (tt "atom") "."))
(def (sig (procedure "(atom-compare-and-set! atom old new)" (id atom-compare-and-set!))) (p "Atomically sets the value of " (tt "atom") " to " (tt "new") " if its current value is " (tt "eq?") " to the given " (tt "old") " value. Returns " (tt "#t") " if the update was successful and " (tt "#f") " if not."))
(def (sig (procedure "(atom-swap! atom proc . args)" (id atom-swap!))) (p "Atomically swaps the value of " (tt "atom") " to be " (tt "(apply proc (atom-value atom) args)") ". Because " (tt "proc") " may be called multiple times it must be free of side-effects. Returns the new value of " (tt "atom") "."))
(def (sig (procedure "(atom-reset! atom value)" (id atom-reset!))) (p "Sets the value of " (tt "atom") " to " (tt "value") ". Returns " (tt "value") "."))
