Surprise list
From Erights
(→Single-letter uriGetters are a special case) |
Kevin Reid (Talk | contribs) (import E surprise list from my web site) |
||
Line 38: | Line 38: | ||
# problem: <ClassCastException: String doesn't coerce to an int> | # problem: <ClassCastException: String doesn't coerce to an int> | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
==<code>def x</code> doesn't return <var>x</var>== | ==<code>def x</code> doesn't return <var>x</var>== | ||
Line 66: | Line 53: | ||
# value: <Promise> | # value: <Promise> | ||
- | === | + | ===Reason and Uses=== |
- | If you want to pass a resolver as an argument | + | If you want to pass a resolver as an argument, this syntax is helpful: |
x.hereIsAResolver(def y) | x.hereIsAResolver(def y) | ||
Line 83: | Line 70: | ||
This has been discussed in [http://www.eros-os.org/pipermail/e-lang/2005-July/010821.html an e-lang thread]. | This has been discussed in [http://www.eros-os.org/pipermail/e-lang/2005-July/010821.html an e-lang thread]. | ||
- | === | + | ===Reason and Uses=== |
This cannot be fixed without removing [http://www.erights.org/elib/distrib/pipeline.html pipelining], eliminating one of the major benefits of the E reference model. | This cannot be fixed without removing [http://www.erights.org/elib/distrib/pipeline.html pipelining], eliminating one of the major benefits of the E reference model. | ||
Line 94: | Line 81: | ||
To avoid being vulnerable to this type of misbehavior, do not use a sameness test (<code>==</code>) or Map key lookup in order to decide on the reliability of the response to a ''previously'' sent message. This might involve using a when-catch/whenResolved construct to wait until the reference is resolved. | To avoid being vulnerable to this type of misbehavior, do not use a sameness test (<code>==</code>) or Map key lookup in order to decide on the reliability of the response to a ''previously'' sent message. This might involve using a when-catch/whenResolved construct to wait until the reference is resolved. | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
[[Category:E language]] | [[Category:E language]] |
Revision as of 18:51, 12 June 2009
Potentially surprising parts of the E language.
Current as of E 0.8.33o.
Contents |
For-loop pattern failure is not an error
If the key or value pattern of a for
loop does not match, then the loop simply skips that element of the collection. This can be useful, but is unlike all other non-explicit pattern match operations (def
and parameter lists).
Examples
# E sample ? def things := [1, "two", 3] # value: [1, "two", 3] ? for x :int in things { > println(x) > } # stdout: 1 # 3 #
Alternative
Move the pattern into a def
:
# E sample ? for thing in things { > def x :int := thing > println(x) > } # stdout: 1 # # problem: <ClassCastException: String doesn't coerce to an int>
def x
doesn't return x
The forward declaration expression, def var
, does not return var but rather the Resolver for it.
Examples
# E sample ? def x # value: <Resolver> ? x # value: <Promise>
Reason and Uses
If you want to pass a resolver as an argument, this syntax is helpful:
x.hereIsAResolver(def y) ... use y
Alternative
If you want the actual promise, simply write (def x; x)
.
Unresolved references do not necessarily behave as their future resolved identity
— messages sent before the reference is resolved may be reacted to however the current holder of the reference “arrow-head” chooses, which does not necessarily correspond to the reference to which the unresolved reference resolves.
This has been discussed in an e-lang thread.
Reason and Uses
This cannot be fixed without removing pipelining, eliminating one of the major benefits of the E reference model.
Examples
For now, see this lengthy example by MarkM.
Alternative
To avoid being vulnerable to this type of misbehavior, do not use a sameness test (==
) or Map key lookup in order to decide on the reliability of the response to a previously sent message. This might involve using a when-catch/whenResolved construct to wait until the reference is resolved.