Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Sather immutable class efficiency/example
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 13th November 03:26
obliviemo
External User
 
Posts: 1
Default Sather immutable class efficiency/example



It's nice to handle program arguments in a single line. It can be
done with a little class like the following, which you can keep


raw with a few lines like

if args.size < 4 then ...
a::=#INT(args[1]);
...
#OUT+tak(a,b,c)+"\n";

within the main routine. I guess that's not surprising. But the time
is _less_ than the raw time when ARGS3INT is an immutable class. That
pleased me and might interest you, gentle reader.

--Mike

-------------------------------------------------------------------------
-- -*-Sather-*-
-- $Id: tak.sa,v 1.2 2003/07/01 11:43:30 mtw Exp $
-------------------------------------------------------------------------
immutable class ARGS3INT is
create(rg:ARRAY{STR}):SAME is
if rg.size < 4 then
raise rg[0]+": need 3 integer args."
end;
-- res ::= new;
-- res.i := #INT(rg[1]);
-- res.j := #INT(rg[2]);
-- res.k := #INT(rg[3]);
res:SAME;
res := res.i(#INT(rg[1])).j(#INT(rg[2])).k(#INT(rg[3]));
return res
end;

attr i,j,k:INT;

val:TUP{INT,INT,INT} is
t:TUP{INT,INT,INT} := t.t1(i).t2(j).t3(k);
return t
end

end;
----------------------------------------------------------------------
class MAIN is

tak(x,y,z:INT):INT
-- Takeuchi function. Try tak(30,20,10). is
if y >= x then
return z
else
return tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y))
end
end;

main(args:ARRAY{STR}) is
v:TUP{INT,INT,INT} := #ARGS3INT(args).val;
#OUT+tak(v.t1, v.t2, v.t3)+"\n"
end

end
  Reply With Quote


  sponsored links


2 13th November 03:27
piotr5
External User
 
Posts: 1
Default Sather immutable class efficiency/example



In article <slrnbg3184.m8q.obliviemo@calypso.view.net.au>,
obliviemo@calypso.view.net.au (Mikelo Obliviemo) writes:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
doesn't "immutable class" mean that here the whole class is copied 3 times?

at least I would be interested in learning as to why the
same thing compiles into different code depending on how
you phrase it. could somebody of the developers explain
why this program compiles the way it compiles?
--
Better send the eMails to netscape.net, as to
evade useless burthening of my provider's /dev/null...

before complaining because of my rudeness, read
http://www.unet.univie.ac.at/~a9702387/en/adl/liar-faq.txt
and killfile me...

P
  Reply With Quote
3 13th November 03:28
ilya minkov
External User
 
Posts: 1
Default Sather immutable class efficiency/example


Did you try comparing the C source? Really interesting.

-i.
  Reply With Quote
4 13th November 03:28
ilya minkov
External User
 
Posts: 1
Default Sather immutable class efficiency/example


No, it's not. This special form of statement configures an immutable
class without copying it more than once, for trivial reasons.


Probably because you can assume that constants don't change? :>

-i.
  Reply With Quote
5 13th November 03:30
obliviemo
External User
 
Posts: 1
Default Sather immutable class efficiency/example


Bear with me. I have a flakey ISP with dreadful propagation. (Not
only for this group.) I seem to be able to post, but not see recent
(or any, it is the luck of the draw) news posted by others. I have
stayed with them out of laziness.

Comment by Ilya seen at groups.google.com:


No, didn't think of it. Since you mention it I will check it out.

-- Mike
  Reply With Quote
6 13th November 03:30
ilya minkov
External User
 
Posts: 1
Default Sather immutable class efficiency/example


Don't rely on your ISP if you don't have to -- mine doesn't offer usenet
access at all.

I was able to find some site where you can search open news server by
the newsgroup, mentioning also its speed and reliability. I'm accessing
the Sather and other comp.lang... newsgroups by

news.so-net.com.hk

....
Oh, i found it again!

http://www.newzbot.com/

-i.
  Reply With Quote
7 13th November 03:30
ilya minkov
External User
 
Posts: 1
Default Sather immutable class efficiency/example


Exactly! Immutable classes with arrays, including strings, save one
degree of indirection by storing the variable-length part together with
the class properties! This also saves malloc overhead, which is
considered to be up to a dozen bytes even for nothing!

-i.
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666