lfe-deprecated / clj

MERGED to LFE - Clojure-inspired macros and functions for use in LFE
28 stars 2 forks source link

Implement doto? #20

Closed yurrriq closed 8 years ago

yurrriq commented 8 years ago

I've got an implementation of doto lying around. Should we include it?

yurrriq commented 8 years ago
(defmacro doto
  "Evaluate all given s-expressions and functions in order,
for their side effects, with the value of `x` as the first argument
and return `x`."
  (`(,x . ,sexps)
   `(let ((,'x* ,x))
      ,@(lists:map
          (match-lambda
            ([`(,f . ,args)] `(,f ,'x* ,@args))
            ([f]             `(,f ,'x*)))
          sexps)
      ,'x*)))
yurrriq commented 8 years ago

This is in https://github.com/rvirding/lfe/pull/267