[Grace-core] Collection naming

Andrew P Black black at cs.pdx.edu
Sun Jun 29 11:43:56 PDT 2014


Right now, each of the collections (sets, lists, dictionaries) has three factory methods. 

type CollectionFactory = { 
    withAll (contents:Collection) -> Collection
    with (*contents:Object) -> Collection
    new (*contents:Object) -> Collection			// deprecated, for backward compatibility with mgcollections
    empty -> Collection
}

There is a trait class that defines three of them in terms of the fourth:

class aCollectionFactoryTrait {
    // requires withAll
    method new(*a) { self.withAll(a) }
    method with(*a) { self.withAll(a) }
    method empty { self.with() }
}

so all that a concrete collection class need do is inherit aCollectionFactoryTrait and define withAll.

It occurred to me that it would be more graceful to just let students write

	set(2, 4, 6, 8)

or
	set()

rather than  aSet.with(2, 4, 6, 8), or aSet.empty, and that if we did that, then perhaps James would stop threatening to add some special syntax for collection literals.  So I set out to do it.

And that's when I realized the problem with the lack of a mechanism for "exploding" an argument list.   We can get rid of .with and .empty and replace them by direct requests on the class, but we really must have .withall.

This doesn't stop me defining a method set(...) as a synonym for aSet.with(...).  But it does stop me from getting rid of the factory methods completely.

I'm getting more and more unhappy with the asymmetry of variable arity methods.

Thoughts?

	Andrew




More information about the Grace-core mailing list