[Aldor-l] export from ...
Christian Aistleitner
tmgisi at gmx.at
Fri Dec 8 06:33:07 EST 2006
Hello,
hopefully this mail is not too off-topic, as I do not discuss the real
problem, but present a second workaround.
On Thu, 07 Dec 2006 22:07:27 +0100, Ralf Hemmecke <ralf at hemmecke.de> wrote:
> Via
>
> aldor -gloop
> #include "aldor"
> MachineInteger
>
> one finds among the export of MachineInteger a line
>
> export to IntegerSegment(%)
Just because of one of your previous mails—within the aldor sources of
MachineInteger, there is no “export to” but “export from”.
However, you are correct, my interpreter also prints out the “export to”.
> ---BEGIN aaa.as
> #include "aldor"
> extend MachineInteger: with {elements: () -> Generator %} == add {
> #if WITHSEGMENT
> import from IntegerSegment %;
> #endif
> elements(): Generator % == generate {
> for i: MachineInteger in 1 .. repeat yield i;
> }
> }
> ---END aaa.as
>
> woodpecker:~/scratch>aldor -DWITHSEGMENT aaa.as
> woodpecker:~/scratch>aldor aaa.as
> "aaa.as", line 7:
> for i: MachineInteger in 1 .. repeat yield i;
> ...........................................^
> [L7 C44] #1 (Error) There are no suitable meanings for the operator `..'.
>
> I would have expected that "import from IntegerSegment" were unnecessary
> in that case.
Assuming your example demonstrates a bug, I assume it is treated like any
bug reported to Aldor.org. Therefore, we need workarounds. Let me suggest
another workaround, because your approach actually uses (or may be
interpreted in a way to use) part of the implementation details of
MachineInteger.
Assume by “1 ..” you acutally mean an element of
IntegerSegment( MachineInteger ), I'd consider your code nice and
expressive.
But maybe by “1 ..” you actually mean calling the function „..:
MachineInteger -> IntegerSegment( MachineInteger )” supplied in some way
(export from) by MachineInteger. (Note the subtle difference to the
previous case.) Then your code would exploit knowledge that MachineInteger
provides the “..” via “IntegerSegment( MachineInteger )” itself.
The difference is hard to see, as it actually is only a semantic one.
However, for the second case, let me suggest importing from the domain you
want to extend. In your case, this comes down to
#include "aldor"
import from MachineInteger;
extend MachineInteger: with {
elements: () -> Generator %;
} == add {
elements(): Generator % == generate {
for i: MachineInteger in 1 .. repeat yield i;
}
}
. Because of the import, you bring all functions of MachineInteger into
scope. Especially also those from “export from” statements. Therefore, you
now use the “..” function with the semantics as shown in the second case
above.
Furthermore, the second approach does not require knowledge about where
the “..” function comes from and allows you to hide the workaround within
a macro like
#if EXTENDBUGFOREXPORTEDFUNCTIONSFIXED
macro EXTENDPREAMBLE( domain ) == {}
#else
macro EXTENDPREAMBLE( domain ) == { import from domain; }
#endif
Kind regards,
Christian
More information about the Aldor-l
mailing list