[Fwd: Re: For loop linguistic abstraction (usage)]

Filip Konvička filip.konvicka at logis.cz
Thu Mar 1 09:17:51 CET 2007


-------- Original Mesage --------
From: 	Craig Ugoretz <craigugoretz at gmail.com>


Hello,

      I thank all of you for helping me out.  Shortly after posting the
question, I realized that the loop linguistic abstraction is based upon
declarative programming (and recursion), so I did not have to worry about
assigning a result to the same variable because the variables are on the
stack (per my teminology).

       I much appreciated everyone's advice about using a dictionary.  I
have just been using the CTM book, especially the appendices, to learn about
special functions for lists, records, etc.  Now I found the documentation
for the standard libraries, including ADT's on the Mozart/Oz website.

                                                                 Craig

On 2/26/07, Filip Konvička <filip.konvicka at logis.cz> wrote:
>
> Raphael Collet 26.2.2007 9:28:
> > Filip Konvička wrote:
> >>
> >> You can do this like this
> >>
> >> fun {CalcFreqMap L}
> >>   D={NewDictionary}
> >> in
> >>   fun X in L do
> >>       O N
> >>   in
> >>       {Dictionary.condExchange D X O N}
> >>       N=O+1
> >>   end
> >>   {Dictionary.toRecord freqmap D}
> >> end
> >
> > There is no concurrency at all in the function.  So you don't need the
> > operation Dictionary.condExchange to update the dictionary.  You can
> > separate read and write operations in the dictionary, which makes it a
> > bit more readable, IMHO:
> I don't think it's more readable (maybe because I'm used to it :-))...in
> fact, your code is just a bit more inefficient, since there are multiple
> dictionary lookups per iteration. I've also found out that the A.B:=C
> notation is a very common cause of runtime errors, so I prefer using the
> standard procedure/function call syntax to avoid this.
> >
> > fun {CalcFreqMap L}
> >    D={NewDictionary}
> > in
> >    for X in L do
> >       D.X := {CondSelect D X 0} + 1
> >    end
> >    {Dictionary.toRecord freqmap D}
> > end
> >
> > Note that the call to CondSelect returns D.X if it exists, and 0
> > otherwise.
> I did not know that CondSelect works for dictionaries as well, thanks
> for the info!
>
> Cheers,
> Filip




More information about the mozart-users mailing list