Arc Forumnew | comments | leaders | submitlogin
2 points by Pauan 4531 days ago | link | parent

And another thing I just realized... if I got rid of "new" and instead said that simply calling the trait defines something of that trait... then this solves the dichotomy between [] pattern matching and the type system.

To explain, [1 2 3] is expanded by the parser into (%seq 1 2 3). That is, it is a concrete implementation of the sequence trait. But I can actually combine those two... by having it instead expand to (seq? 1 2 3). And then seq? would be defined something like this:

  $deftrait seq?
    provides immutable?
    provides orderable?
    provides ordered?
    provides iterable?
      ...
That is, it's an abstract trait that accepts 0 or more arguments, is immutable? and orderable? and ordered?. Now, calling (seq? 1 2 3) will create a new "instance" of the trait seq? and using (seq? A B C) with pattern matching will destructure it...

Oh yeah, and I didn't mention before, but I want to provide a pattern-matchable? trait. This lets you define custom behavior when pattern matching. So then the dictionary trait could be defined like so...

  $deftrait dict?
    inherits seq?
    
    provides iterable?
      ...
    
    provides pattern-matchable?
      ...
And I want the ability to remove traits. So you could create a dictionary that inherits from seq? but is not immutable:

  $deftrait mutable-dict?
    inherits seq?
    removes immutable?


1 point by rocketnia 4527 days ago | link

While it seems fine to get rid of 'new, your reason for doing so doesn't make sense. Can't (%seq 1 2 3) be implemented as a procedure that calls (new seq? 1 2 3)?

-----