From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sat, 19 May 2007 02:38:34 -0400 From: Kris Maglione To: 9fans@cse.psu.edu Subject: Re: [9fans] Concurrency and message passing with Newsqueak Message-ID: <20070519063834.GC96831@kris.home> References: <5d375e920705181645y4b665da2tdf8e0049af39e1dd@mail.gmail.com> <7359f0490705182103s7e4341e2ofa7e0d28f04dcc8@mail.gmail.com> <464E7EB8.1000206@conducive.org> <7359f0490705182155o2d137273s561ad7f983bf258a@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bAmEntskrkuBymla" Content-Disposition: inline In-Reply-To: <7359f0490705182155o2d137273s561ad7f983bf258a@mail.gmail.com> User-Agent: Mutt/1.5.15 (2007-04-06) Topicbox-Message-UUID: 6c1029ac-ead2-11e9-9d60-3106f5b1d025 --bAmEntskrkuBymla Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 18, 2007 at 09:55:37PM -0700, Rob Pike wrote: > The Haskell version is quite pretty but almost a special case due > to the way lazy lists work. The power series program also comes > out quite well in Haskell. The systems examples I talked about > don't work quite so well, I believe. Channels are not really the > same as lazy lists. Haskell's lazy lists make for one of the most beautiful implementations=20 I've seen, and I agree that the CSP implementations is one of the most=20 beautiful pieces of code I've seen. If we're to compare channels to any=20 language feature, though, why not closures? I won't argue for replacing=20 one with the other of course, but there are some interesting=20 similarities. It's apparant to most readers that the CSP implementation=20 is basically checking that each number is 0 modulo any of the previous=20 primes, so applying a lambda to a list of previous primes immediately=20 came to mind. But this first implementation is almost an exact mapping=20 of the CSP implementation into lambdas and closures. Each new channel is=20 replaced with a new closure around the same lambda (the first being the=20 exception, as in CSP). I've also implemented it in Limbo, for the hell=20 of it, and for the sake of the topic. :) As it turns out, the first implementation is the fastest. (defun get-sieve () (let* ((n 1) (fn (lambda () (incf n)))) (lambda () (let ((n (funcall fn)) (f fn)) (labels ((me () (let ((m (funcall f))) (if (=3D (mod m n) 0) (me) m)))) (setf fn #'me) n))))) (defun get-sieve () (let ((n 1) (list nil)) (labels ((prime (n) (if (member-if (lambda (x) (=3D (mod n x) 0)) list) (prime (1+ n)) n))) (lambda () (prog1 (setf n (prime (1+ n))) (setf list (cons n list))))))) (defun primes (num) (let ((sieve (get-sieve))) (dotimes (n num) (print (funcall sieve))))) (defun getprimes (num) (let ((sieve (get-sieve))) (do ((n 0 (funcall sieve))) ((> n num)) (print n)))) nofactor(aux: int, l: list of int): int { for(; l !=3D nil; l =3D tl l) if(aux % hd l =3D=3D 0) return 0; return 1; } primes(num: int) { l : list of int; n :=3D 2; for(i :=3D 0; i < num; n++) { if(nofactor(n, l)) { l =3D n :: l; i++; sys->print("%d\n", n); } } } --=20 Kris Maglione In any hierarchy, each individual rises to his own level of incompetence, and then remains there. --bAmEntskrkuBymla Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.3 (FreeBSD) iD8DBQFGTptqseQZD8Aui4wRAnYzAKCIzLcDCpUS8zFZO1AHyDHQixFSTwCffDCJ rkOqdG7rRHKaYMuWK+zL6yU= =Zul5 -----END PGP SIGNATURE----- --bAmEntskrkuBymla--