From: MenTaLguY Date: 2006-02-23T14:55:48+09:00 Subject: Re: [ANN] lazy.rb 0.9.5 -- transparent futures! --=-7OsrmbmAp5BzN0ssKKlb Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, 2006-02-23 at 13:21 +0900, Daniel Nugent wrote: > However, currently, there IS a block parameter (that of the promise > itself, something to do with circular programming, which sounds > intriguing, but I have hella no idea what it means [PLEASE SEND > LINKS]), but it doesn't seem like you'd use it in most cases. Here are a couple trivial examples... Building a circular data structure (a linked list in this case): def build_circular_list( *stuff ) promise { |result| if stuff.empty? nil else list =3D result stuff.reverse.each { |thing| list =3D [ thing, list ] } list end } end Padding lines of text to a maximum width in a single pass: def pad_lines( lines ) promise { |result| max_width =3D 0 padded_lines =3D [] lines.each { |line| max_width =3D line.length if line.length > max_width padded_lines.push promise { "%*s" % [ result[1], line ] } } [ padded_lines, max_width ] }[0] end -mental --=-7OsrmbmAp5BzN0ssKKlb Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBD/U6PSuZBmZzm14ERAoDdAKDYMyJeJR0584v71t3Brkfe4VcGuwCfR3ou ESQoYd6MrP3TXz1Wisg+wfo= =ldfL -----END PGP SIGNATURE----- --=-7OsrmbmAp5BzN0ssKKlb--