#100 Making __conformTo and __optSealedDispatch prettier

feature_request
open
1
2005-06-01
2005-06-01
No

At
http://www.eros-os.org/pipermail/e-lang/2004-April/009820.html
Kevin Reid writes:

It occurs to me that __conformTo and
__optSealedDispatch are very
similar in the code required to implement them. Adding
expansions for
defining __optSealedDispatch cases has been discussed
before; the same
could work for __conformTo. Here's a possible syntax:

def textWriterWrapper {
to __conformTo match (==TextWriter) :any { return
actualWriter }
}

(I am not suggesting that this be added to E now, but
rather that
if/when such an expansion is added, perhaps it should
look like this.)

This is exactly like a regular 'to' method, except that
if its argument
pattern does not match, instead of throwing an
exception, it continues
to the 'next' method of that name, which is the first
available of:

1. another 'match' method textually after it

An additional case.

2. a non-'match' method (possibly required to be after
it for
clarity)

The default case, like 'else { return textWriterWrapper }'

3. A miranda method.

The default case for __conformTo and __optSealedDispatch.

This would require a new primitive (to be used in the
expansion)
to allow invoking the miranda methods, but this is
something that
should be added anyway.

4. The object's matcher.

This would require a new primitive.

(Note that the __respondsTo and __getAllegedType
mirandas essentially
do 3->4 calling already.)

Example expansion:

def thing {
to __optSealedDispatch match (==fooBrand) :any { return
fooSealer.seal(foo) }
to __optSealedDispatch match (==barBrand) :any { return
barSealer.seal(bar) }
}

expands (partially) to:

def thing {
to __optSealedDispatch(arg_1) :any {
switch (def args_1 := [arg_1]) {
match [==fooBrand] {
def res_2 :any := escape __return { return
fooSealer.seal(foo) }
res_2
}
match [==barBrand] {
def res_3 :any := escape __return { return
barSealer.seal(bar) }
res_3
}
match _ {
# this is a meta expression so that 'thing' is required to
be an
# enclosing definition, rather than an arbitrary reference.
#
# meta.callImplicit(target, verb) acts as E.call except
that it
# ignores normal methods, invoking miranda methods or
matchers.
# This implements items 3 and 4 above.
meta.callImplicit(thing, "__optSealedDispatch", args_1)
}
}
}
}

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks