Arc Forumnew | comments | leaders | submitlogin
3 points by absz 5898 days ago | link | parent

I like it! Though it'd probably be better to use an optional parameter rather than a variadic function for what you're focusing on:

  (mac focus (var . body)
    (w/uniq (storage unbound)
      `(withs (,storage nil
               ,var     (fn ((o arg ',unbound))
                          (if (is arg ',unbound)
                            ,storage
                            (= ,storage arg))))
         ,@body
         (when (is arg ',unbound)
           ,storage))))
(And you'll notice that since arg is lexical, you don't need to make it a gensym.)


4 points by drcode 5898 days ago | link

Your definition has a typo, I think- What you probably meant is:

  (mac focus (var . body)
    (w/uniq (storage unbound)
      `(withs (,storage nil
               ,var (fn ((o arg ',unbound))
                      (if (is arg ',unbound)
                          ,storage
                          (= ,storage arg))))
         ,@body  
         ,storage)))

-----

1 point by drcode 5898 days ago | link

I thought about that, but then thought it would prevent you from returning 'nil... but your solution handles that case.

I agree your definition is better.

-----