Arc Forumnew | comments | leaders | submitlogin
as-expressions in wart
2 points by akkartik 4187 days ago | discuss
You wouldn't write it like this, but you could:

  def (pair? (x | (first ... (rest | (second ... rest2)))))
    (and list?.x
         list?.rest
         no.rest2)
I'm currently not using as-patterns for pattern matching, just destructuring:

  def (copy (x | (head ... tail)))
    if (~bound? 'head)   # enter even if x is not a list
      x
      (cons copy.head copy.tail)
I'm not sure how useful this is; every use case I've seen for it seems worse than just using car and cdr. Thoughts?

P.S. Building this feature turned out to be shockingly easy: http://github.com/akkartik/wart/commit/90646d3980