JanetDocsPlaygroundI'm feeling luckyGitHub sign in

with-syms



    macro
    boot.janet on line 311, column 1

    (with-syms syms & body)

    Evaluates `body` with each symbol in `syms` bound to a generated, 
    unique symbol.


1 exampleSign in to add an example
Loading...
(defmacro timeit [& body]
    # generate unique symbols to use in the macro so they can't conflict with anything used in `body`
    (with-syms [$t0 $t1]
        ~(do
            (def $t0 (os/clock :monotonic :double))
            (do ,;body)
            (def $t1 (os/clock :monotonic :double))
            (- $t1 $t0))))

(def time-taken (timeit (os/sleep 0.5)))
(printf "Took %.3f seconds" time-taken)
AndriamanitraPlayground