Arc Forumnew | comments | leaders | submitlogin
2 points by rocketnia 4761 days ago | link | parent

"Yes, except rocketnia doesn't like coerce either."

For the record, that's true, but I do follow a coercion pattern sometimes. See the end of http://arclanguage.org/item?id=14220: "To digress a bit, coercion is a positively useful design pattern when...."

As it happens, 'each is one of those times I'd use a coercion pattern. I'd probably define these utilities, with these dependencies:

  each  -->  some  -->  seqify  -->  entries  -->  keys  -->  unwrap-my-table
To introduce the type 'my-table and give it support for 'each, I only need to extend 'keys so that it tries 'unwrap-my-table.[1] If I do that, 'seqify will already be able to coerce my type to a lazy list.

[1] If the system doesn't support failcall, I may also have to extend 'supports-keys so that it tries 'isa-my-table. The diagram would be about twice as big if I included these predicates.