clay icon indicating copy to clipboard operation
clay copied to clipboard

Attribute blocks

Open jckarter opened this issue 13 years ago • 4 comments

As suggested by @galchinsky, it would be useful to be able to collect top level definitions with common attributes into a block, to eliminate repetition:

forceinline {
  foo() {}
  bar() {}
}

[T when Foo?(T)] {
    foo(x:T) {}
    bar(x:T) {}
}

jckarter avatar Oct 16 '12 04:10 jckarter

This had already been proposed and I had considered implementing it a few months ago. However the natural progression lead to nesting of these groups which looked a bit messy. Would you allow attribute/predicate refinement within the proposed blocks?

ghost avatar Oct 16 '12 11:10 ghost

Arbitrary nesting seems like overkill. Allowing simple refinement seems doable. If a definition in a predicated block has an additional predicate, consider it to have the and of the block's and the definition's predicate. So:

[T when Sequence?(T)] {
    [E when SequenceElementType(T) == E] push(seq:T, elt:E) { ... }
}

would be equivalent to:

[T, E when Sequence?(T) and SequenceElementType(T) == I]
push(seq:T, elt:E) { ... }

Attribute sets would be unioned. More complex combinations shouldn't be required, because you can always not use blocks if they aren't appropriate.

jckarter avatar Oct 16 '12 15:10 jckarter

What about mixing predicates & multiple attributes?

[T when Bar?(T)] inline {
    ...
}

ghost avatar Oct 22 '12 15:10 ghost

If we're going to allow either predicate or attribute blocks, allowing both together makes sense.

jckarter avatar Oct 22 '12 16:10 jckarter