Rob Pike's Newsqueak - some good concepts

Dejan Lekic dejan.lekic at gmail.com
Fri May 18 06:02:30 PDT 2007


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!



More information about the Digitalmars-d mailing list