Arc Forumnew | comments | leaders | submitlogin
1 point by conanite 5431 days ago | link | parent

"me too!!!"

I totally have to remind myself every time that it's "ontable" for tables, not "each"

The (each (k v) h ...) syntax feels like a natural destructuring way to iterate over a table. And the cost of an extra pair of parens is more than offset by having an each that behaves the way you'd expect it to.



3 points by rntz 5431 days ago | link

Thirded. I'd very much like to see this get into arc3's final release. This makes iterating over a given table just like iterating over the corresponding association list.

It's a single-line patch:

    diff --git a/arc.arc b/arc.arc
    index a2a6a8d..ac5ea3e 100644
    --- a/arc.arc
    +++ b/arc.arc
    @@ -467,7 +467,7 @@
                      (self (cdr ,g))))
                  ,gseq)
                (isa ,gseq 'table)
    -            (maptable (fn (,g ,var) ,@body)
    +            (maptable (fn ,var ,@body)
                           ,gseq)
                 (for ,g 0 (- (len ,gseq) 1)
                   (let ,var (,gseq ,g) ,@body))))))

-----

1 point by CatDancer 5429 days ago | link

This makes iterating over a given table just like iterating over the corresponding association list

That's a cool point!

If calling a list wasn't already doing a lookup by position, I might like a call on a cons to do an alref so that I could use x!foo to do a lookup by 'foo whether x was a table or an assoc list.

-----

2 points by CatDancer 5431 days ago | link

It's a single-line patch if no other code in Arc/News uses each with tables...

-----