Arc Forumnew | comments | leaders | submitlogin
3 points by fallintothis 5159 days ago | link | parent

It'd be easy, since ac.scm just changes ~foo into (complement foo) (except (~foo x) is changed to (no (foo x)), but that doesn't affect us here). Just change complement.

  (mac complement (f)
    (w/uniq (gf args)
      `(let ,gf ,f
         (if (isa ,gf 'fn)
             (fn ,args (no (apply ,gf ,args)))
             (no ,gf)))))

  arc> (= foo "bar")
  "bar"
  arc> ~foo
  nil
  arc> (keep ~even '(1 2 3))
  (1 3)
  arc> ~nil
  t
  arc> ~
  #<procedure: no>
But I don't think I've ever made that slip. Function complementation isn't the same as Boolean-not, so overloading the visually distinctive ~foo based on context rubs me the wrong way. I'd probably get used to it, though.

Edit:

Another thought occurs. It could produce some weird bugs. E.g., you might mistakenly pass a variable to a keep that complements, which will work, but keeps t or nil instead of using a function.

  arc> (= foo "bar")
  "bar"
  arc> (keep ~ssyntax '(a.b a:b nil a b c))
  (nil a b c)
  arc> (keep ~foo '(a.b a:b nil a b c))
  (nil)
  arc> (keep ~nil '(a.b a:b nil a b c))
  nil
It doesn't seem so bad, but when you have it buried in some definition like

  (def foo (bar baz)
    (...  (keep ~bar baz) ...))
it might be hard to find.