[Aldor-l] Should this "parser" work?

Christian Aistleitner tmgisi at gmx.at
Tue Oct 24 02:31:26 EDT 2006


Hello,

On Mon, 23 Oct 2006 09:39:00 +0200, Martin Rubey  
<martin.rubey at univie.ac.at> wrote:

>> First of all, what do you mean by “instance of Atom”. Atom is a  
>> domain.  For
>> the domain MachineInteger, 34 is an instance, just as 35 or 36 are.   
>> But for
>> Atom?
>
> I'd think that domains are instantiated, since it may happen that they  
> contain some local data. But that's a very vague idea.

still I do not understand, what you mean by “instantiated”.
My interpetation of “instantiate” merely coincides with that of
http://en.wikipedia.org/wiki/Object_(computer_science)#Objects_in_object-oriented_programming

I know that Aldor is not an OO language. But the differences are not  
important for the meaning of “insntantiate”.

So again, what do you mean by “instance of a domain Atom”? When does that  
happen? What is it good for?

>> You probably mean “some copy/reference of/to the domain”. But I do not   
>> think,
>> something like that happens.
>
> However, I just found the following remark in the AUG:
>
>
> 20.3        Fortran-77 has a fixed and relatively small set of data  
> types, and
>             passes all subprogram parameters by reference (i.e. it  
> passes a
> Data Corre- pointer to the data rather than a copy of the data). Aldor,  
> on the
> spondence   other hand, has a rich and extensible type system, and in  
> general
>             will pass copies of subprogram data (at least in simple  
> cases). The
>             aim of the interface is to ensure that Foreign functions  
> behave
>             naturally in their host environment.
>
> Does this apply to the present situation? I.e., wouldn't this mean, for
> instance, that "cons" in
>
>         res: List CC := [];
>         for x in p repeat
>           res := cons(Atom, res);
>
> will copy "Atom"? (and "res"???)

I think, it does not apply.
Consider the following piece of code:

#include "aldor"

import from String;
import from TextWriter, Character, MachineInteger;


Cat: Category == with {
         getMagicNumber: () -> MachineInteger;
         setMagicNumber: MachineInteger -> ();
};

Dom: Cat == add {
         local magicNumber: MachineInteger := 0;

         getMagicNumber(): MachineInteger == {
                 free magicNumber;
                 magicNumber;
         }

         setMagicNumber( a: MachineInteger ): () == {
                 free magicNumber;
                 magicNumber := a;
         }

}


set( D: Cat, a: MachineInteger ): () == {
         import from D;
         setMagicNumber( a );
}

dump( D: Cat ): () == {
         import from Trace, D;
         stdout << (name(D)) << "   " << (getMagicNumber()) << newline;
}

dump( Dom );

set( Dom, 4 );

dump( Dom );



If you are right, how can you explain this output
____________________________________________
tmgisi at spencer
cwd: ~/aldor
$ LC_ALL=C /opt/aldor/bin/aldor -M no-abbrev -C args=-Wopts=-m32 -Fx -l  
algebra -l aldor test.as && ./test
cc1: note: -fwritable-strings is deprecated; see documentation for details
cc1: note: -fwritable-strings is deprecated; see documentation for details
Dom   0
Dom   4


According to your interpretation, within set, D is a copy of Dom. So  
setting the magic number of this copy must not affect Dom's magic number.  
However, it does.

--
Kind regards,
Christian



More information about the Aldor-l mailing list