Rob Pike's Newsqueak - some good concepts

Daniel Keep daniel.keep.lists at gmail.com
Fri May 18 12:17:36 PDT 2007



Dejan Lekic wrote:
> Today I watched an excellent presentation by Mr. Rob Pike on Google Tech Talks. (Advanced Topics in Programming Languages: Concurrency/message passing Newsqueak - http://video.google.com/url?docid=810232012617965344&esrc=rss_uds&ev=v&q=user:%22Google+engEDU%22&vidurl=http://video.google.com/videoplay%3Fdocid%3D810232012617965344%26q%3Duser%253A%2522Google%2BengEDU%2522%26hl%3Den&usg=AL29H22XDZMMUfZudHDB2dqX9jtFEE4L9w )
> There are several very interesting concepts in his Newsqueak langauge which I would be very happy to see in D. One of such is the ability to execute ANY function as a new process (thread) via keyword "begin".
> An example:
> <code>
> // makes no sense, but should work
> begin int sum(int a, int b) { return a+b; } 
> 
> begin int doConcurrently(int a, int b)
> {
>   for (; a>0; a--)
>     print(b);  // prints in background
> }
> 
> // same, like lambda
> begin int doConcurrently2(int a, int b)
> {
>   for (; a>0; a--)
>     print(b);  // prints in background
> }(20, sum(23, 5))
> </code>
> 
> As You can see, begin makes expression/function work in a separate process/thread. It has been discussed about having lambda-functions here on these newsgroups, so I will not touch that topic in this thread...
> 
> Second very interesting concept is connected with the "become" keyword. With it you can replace function with it's execution, which basically generalizes tail recursion. This is better explained with an example:
> <code>
> // Any expression
> int function(int a, int b) { become a + b; }
> 
> int sum(int a, int b)
> {
>   return a+b;
> }
> 
> // Any function invocation
> // Reuses sum's stack space!
> int difference(int a, int b) 
> {
>   become sum(a, -b);
> }
> </code>
> 
> There are more interesting things, I haven't had time to write about them, so I strongly recommend seeing this presentation! :)
> 
> Cheers!

Both are pretty cool, but the first sounds a lot like the future
function myself and someone else wrote a while back.  Forgive me if I'm
misunderstanding, but it basically moves "begin" to the point of use:

> int sum(int a, int b) { return a+b; }
>
> // ...
>
> auto result = future(sum, 38, 4);
> // Do something else
> assert( result.value == 42 ); // .value blocks until other thread has
>                               // computed the result

I'm not sure where mine got to, but I'm pretty sure the other one is in
scrapple on dsource.org/projects/scrapple.

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list