[ANN] lazy.rb 0.9.5 -- transparent futures!

M

MenTaLguY

--=-Nhoy1n60Sqvzvq/VUinT
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

I'd like to announce a new version of lazy.rb -- this one offering
thread safety and transparent futures!

Here's the web site, complete with gem and tarball downloads, plus a bit
of documentation:

http://moonbase.rydia.net/software/lazy.rb/

Bug reports would be very, very welcome.

=3D=3D What is lazy.rb?

lazy.rb is a library providing transparent lazy evaluation and futures
for Ruby. It provides a bag of clever tricks to help you avoid doing
expensive computations up front.

=3D Lazy Evaluation

Lazy evaluation simply refers to computations which are run on an
as-needed basis. For example:

x =3D promise { 3 + 5 }

Means that the block -- 3 + 5 -- won't actually be evaluated until
something tries to use x's value.

p x # =3D> #<Lazy::promise computation=3D#<Proc:...>>

# forces evaluation
p x * 3 # =3D> 24

p x # =3D> 8

You can also force evaluation using demand:

x =3D promise { 3 + 5 }

p x # =3D> #<Lazy::promise computation=3D#<Proc:...>>

# forces evaluation
p demand( x ) # =3D> 8

p x # =3D> 8

It's a bit silly for 3 + 5, but it's handy for more intensive
calculations. You can unconditionally promise a computation, yet only
pay for it if and when its result is actually used.

=3D Futures

Futures are blocks of code that are evaluated immediately, but in a
background thread.

x =3D future { 3 + 5 }

p x # =3D> #<Lazy::Future computation=3D#<Proc:...>>

# You could do other stuff here while
# the computation ran in the background

# blocks until the background thread completes
p x * 3 # =3D> 24
=20
p x # =3D> 8

Again, silly for 3 + 5 perhaps, but I'm sure you can see how this might
come in handy for more involved computations.

=3D Other stuff

lazy.rb also includes support for circular programming, where a
computation is passed its own result:

matryoshka =3D demand( promise { |result| [result] } )

p matryoshka # =3D> [[...]]

p matryoshka.object_id # =3D> -605506544

p matryoshka.first.object_id # =3D> -605506544

p matryoshka.first.first.object_id # =3D> -605506544

This works for both promises and futures, although it has the usual
limitations: if a computation tries to call methods on its own result,
it will diverge.

=3D=3D What's new in 0.9.5?

- Optional support for multithreaded programs:

require 'lazy/threadsafe' and you can safely use lazy evaluation in
multithreaded programs.

- Futures:

With thread support, it turned out that futures were really
easy to implement atop promises -- just fire off a thread with the
computation and return a promise to join the thread and grab its
result. So I implemented that.

=3D=3D What happened to lazy streams from 0.2?

I ditched the lazy streams API for now. It just wasn't working out.

=3D=3D What next?

Except perhaps for lazy streams (which might end up becoming a separate
library), I think we're nearly feature-complete. Ideas and suggestions
are very welcome, though.

-mental

--=-Nhoy1n60Sqvzvq/VUinT
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)

iD8DBQBD98ThSuZBmZzm14ERAsBEAKC3KiMZu7WOFk4B1uVo/C8KqKfzEACfbdXS
sPMwxcD9UxGUwXrmkuxjM6E=
=P4qy
-----END PGP SIGNATURE-----

--=-Nhoy1n60Sqvzvq/VUinT--
 
I

itsme213

MenTaLguY said:
I'd like to announce a new version of lazy.rb -- this one offering
thread safety and transparent futures!
Nice.

# forces evaluation
p x * 3 # => 24

What will it do for:
p 3 * x

Thanks for sharing.
 
M

matt.smillie

If you suspected "the right thing" you'd probably be right:

irb(main):001:0> require 'lazy'
irb(main):002:0> x = promise { 5 + 3 }
=> #<Lazy::promise computation=#<Proc:0x0035788c@(irb):2>>
irb(main):003:0> p 3 * x
24
=> nil
 
A

Andrew Johnson

--=-Nhoy1n60Sqvzvq/VUinT
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

I'd like to announce a new version of lazy.rb -- this one offering
thread safety and transparent futures!

Here's the web site, complete with gem and tarball downloads, plus a bit
of documentation:

http://moonbase.rydia.net/software/lazy.rb/

Bug reports would be very, very welcome.


When I toyed with a proof-of-concept of Io's asynchronous messages in Ruby

http://www.siaris.net/index.cgi/Programming/LanguageBits/Ruby/Async.rdoc

Jim Weirich pointed out that methods later added to Object or Kernel will
no longer be "missing" in the Async (or Future) class. One work around is
to trap "method_added" up the chain, for example:

http://www.siaris.net/cgi-bin/siwiki.pl?FeedBack/AsyncMessages

But then I discovered that methods added by including a module weren't
trapped by method_added -- so in the end, a KernellessObject (from evil.rb)
was needed (same link as above) as Async's parent to keep the proxy clean.

regards,
andrew
 
M

Minkoo Seo

Sorry for newbie question. I tried to install lazy only to fail:

[root@poseidon tmp]# ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]
[root@poseidon tmp]# ls -l lazy-0.9.5.gem
-rw-r--r-- 1 mkseo users 6656 2ì›” 19 09:31 lazy-0.9.5.gem
[root@poseidon tmp]# gem install lazy-0.9.5.gem
Attempting local installation of 'lazy-0.9.5.gem'
Successfully installed lazy, version 0.9.5
Installing RDoc documentation for lazy-0.9.5...

lazy.rb:60:22: Couldn't find DIVERGES. Assuming it's a module
[root@poseidon tmp]#

Any idea?

Minkoo Seo
 
J

Jim Weirich

Minkoo said:
Sorry for newbie question. I tried to install lazy only to fail:

[root@poseidon tmp]# ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]
[root@poseidon tmp]# ls -l lazy-0.9.5.gem
-rw-r--r-- 1 mkseo users 6656 2ì›” 19 09:31 lazy-0.9.5.gem
[root@poseidon tmp]# gem install lazy-0.9.5.gem
Attempting local installation of 'lazy-0.9.5.gem'
Successfully installed lazy, version 0.9.5
^^^^^^^^^^^^

The installatiof of the lazy software is OK ...
Installing RDoc documentation for lazy-0.9.5...

lazy.rb:60:22: Couldn't find DIVERGES. Assuming it's a module

Its just that RDoc is complaining about something. I got the same error
on my system, but the RDoc looks ok, even with the error.
 
M

Minkoo Seo

Still, no luck.

[root@poseidon tmp]# ll
합계 12
-rw-r--r-- 1 mkseo users 6656 2ì›” 19 09:31 lazy-0.9.5.gem
[root@poseidon tmp]# gem install lazy-0.9.5.gem
Attempting local installation of 'lazy-0.9.5.gem'
Successfully installed lazy, version 0.9.5
Installing RDoc documentation for lazy-0.9.5...

lazy.rb:60:22: Couldn't find DIVERGES. Assuming it's a module
[root@poseidon tmp]# irb
irb(main):001:0> require 'lazy'
LoadError: no such file to load -- lazy
from (irb):1:in `require'
from (irb):1
irb(main):002:0> require 'lazy/future'
LoadError: no such file to load -- lazy/future
from (irb):2:in `require'
from (irb):2
irb(main):003:0>

[root@poseidon tmp]# ls -l /usr/local/lib/ruby/gems/1.8/gems/
합계 72
drwxr-xr-x 4 root root 4096 2ì›” 12 07:32 actionmailer-1.1.5/
drwxr-xr-x 5 root root 4096 2ì›” 12 07:32 actionpack-1.11.2/
drwxr-xr-x 5 root root 4096 2ì›” 12 07:32 actionwebservice-1.0.0/
drwxr-xr-x 5 root root 4096 2ì›” 12 07:31 activerecord-1.13.2/
drwxr-xr-x 3 root root 4096 2ì›” 12 07:31 activesupport-1.2.5/
drwxr-xr-x 3 root root 4096 2ì›” 22 00:42 lazy-0.9.5/
drwxr-xr-x 11 root root 4096 2ì›” 12 07:32 rails-1.0.0/
drwxr-xr-x 6 root root 4096 2ì›” 12 07:31 rake-0.7.0/
drwxr-xr-x 3 root root 4096 2ì›” 12 07:30 sources-0.0.1/


[root@poseidon tmp]# ls -l /usr/local/lib/ruby/1.8/ | grep lazy
[root@poseidon tmp]#

I've taken the liberty of posting installation problem to this post,
because this is the first time for me to install local *.gem file.
Can anybody tell me why this is happening? Isn't the lazy.rb file
supposed to be installed in /usr/local/lib/ruby/1.8 ?

- Minkoo Seo
 
R

Ross Bamford

Still, no luck.
=20
[root@poseidon tmp]# ll
=ED=95=A9=EA=B3=84 12
-rw-r--r-- 1 mkseo users 6656 2=EC=9B=94 19 09:31 lazy-0.9.5.gem
[root@poseidon tmp]# gem install lazy-0.9.5.gem
Attempting local installation of 'lazy-0.9.5.gem'
Successfully installed lazy, version 0.9.5
Installing RDoc documentation for lazy-0.9.5...
=20
lazy.rb:60:22: Couldn't find DIVERGES. Assuming it's a module
[root@poseidon tmp]# irb
irb(main):001:0> require 'lazy'
LoadError: no such file to load -- lazy
from (irb):1:in `require'
from (irb):1
irb(main):002:0> require 'lazy/future'
LoadError: no such file to load -- lazy/future
from (irb):2:in `require'
from (irb):2
irb(main):003:0>

Haven't followed this thread all the way, but I'm assuming you must have
already tried:

$ irb
require 'rubygems'
require 'lazy'

Or alternatively passing -rubygems as an option to IRB.

--=20
Ross Bamford - (e-mail address removed)
 
L

Logan Capaldo

Still, no luck.

[root@poseidon tmp]# ll
=ED=95=A9=EA=B3=84 12
-rw-r--r-- 1 mkseo users 6656 2=EC=9B=94 19 09:31 lazy-0.9.5.gem
[root@poseidon tmp]# gem install lazy-0.9.5.gem
Attempting local installation of 'lazy-0.9.5.gem'
Successfully installed lazy, version 0.9.5
Installing RDoc documentation for lazy-0.9.5...

lazy.rb:60:22: Couldn't find DIVERGES. Assuming it's a module
[root@poseidon tmp]# irb
irb(main):001:0> require 'lazy'
LoadError: no such file to load -- lazy
from (irb):1:in `require'
from (irb):1
irb(main):002:0> require 'lazy/future'
LoadError: no such file to load -- lazy/future
from (irb):2:in `require'
from (irb):2
irb(main):003:0>

[root@poseidon tmp]# ls -l /usr/local/lib/ruby/gems/1.8/gems/
=ED=95=A9=EA=B3=84 72
drwxr-xr-x 4 root root 4096 2=EC=9B=94 12 07:32 actionmailer-1.1.5/
drwxr-xr-x 5 root root 4096 2=EC=9B=94 12 07:32 actionpack-1.11.2/
drwxr-xr-x 5 root root 4096 2=EC=9B=94 12 07:32 = actionwebservice-1.0.0/
drwxr-xr-x 5 root root 4096 2=EC=9B=94 12 07:31 = activerecord-1.13.2/
drwxr-xr-x 3 root root 4096 2=EC=9B=94 12 07:31 = activesupport-1.2.5/
drwxr-xr-x 3 root root 4096 2=EC=9B=94 22 00:42 lazy-0.9.5/
drwxr-xr-x 11 root root 4096 2=EC=9B=94 12 07:32 rails-1.0.0/
drwxr-xr-x 6 root root 4096 2=EC=9B=94 12 07:31 rake-0.7.0/
drwxr-xr-x 3 root root 4096 2=EC=9B=94 12 07:30 sources-0.0.1/


[root@poseidon tmp]# ls -l /usr/local/lib/ruby/1.8/ | grep lazy
[root@poseidon tmp]#

I've taken the liberty of posting installation problem to this post,
because this is the first time for me to install local *.gem file.
Can anybody tell me why this is happening? Isn't the lazy.rb file
supposed to be installed in /usr/local/lib/ruby/1.8 ?

- Minkoo Seo

require 'rubygems'
require 'lazy'
 
M

MenTaLguY

--=-Ipjq4l0d8E/LS+R44yx1
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
 
M

MenTaLguY

--=-5VA/Oo0UU0EvsPL+bnbh
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Its just that RDoc is complaining about something. I got the same error=20
on my system, but the RDoc looks ok, even with the error.

DIVERGES is a nodoc'd constant which is used internally. If anyone can
find a way to avoid the RDoc warning, I'd really appreciate it...

-mental

--=-5VA/Oo0UU0EvsPL+bnbh
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+1yjSuZBmZzm14ERApk4AKDeRDFAmtDHoUnTeWRMCEw0MX/x4ACbBmVK
J23iFWs/si2QlXKARfh+Xos=
=+4aA
-----END PGP SIGNATURE-----

--=-5VA/Oo0UU0EvsPL+bnbh--
 
J

James Edward Gray II

Hmm, good catch. Thanks!

I wonder if it's worth introducing a dependency on evil.rb?

Oh, I don't think so. It would cut off some users, like me. ;)

James Edward Gray II
 
A

Andrew Johnson

Oh, I don't think so. It would cut off some users, like me. ;)

At one point I was going to try to extract a minimum subset of evil
to just allow for KernellessObject, but never got to it. Would such
a small_evil.rb be less of a dependency concern?

andrew
 
J

Jim Weirich

MenTaLguY said:
Hmm, good catch. Thanks!

I wonder if it's worth introducing a dependency on evil.rb?

The BlankSlate class in Builder handles this without resorting to the
"evil" that lies in the heart of evil.rb. And the CVS head version of
BlankSlate also handles the module hole Andrew mentioned earlier (I
think ... I just now updated it).4
 
A

Andrew Johnson

MenTaLguY wrote: [snip]
I wonder if it's worth introducing a dependency on evil.rb?

The BlankSlate class in Builder handles this without resorting to the
"evil" that lies in the heart of evil.rb. And the CVS head version of
BlankSlate also handles the module hole Andrew mentioned earlier (I
think ... I just now updated it).4

That does appear to plug it -- and I even recall looking at
append_features back then and not seeing it. Thanks Jim!

andrew
 
G

gabriele renzi

James Edward Gray II ha scritto:

maybe just making it optional.. you could even make great use of
Object#become :)
 
J

Jim Weirich

MenTaLguY said:
Hmm, that sounds more like it. Any chance of a separate BlankSlate gem?

Ask and ye shall receive:

gem install blankslate --source http://onestepback.org/betagems

This is a quick breakout of the BlankSlate class into its own gem. It
now sits as a top level namespace (instead of being nested in the
Builder module). It is built from the same source as Builder, so the
builder gem still includes the class physically. (Shouldn't be a
problem unless there start to be weird version mismatches).

There are still some documentation issues (e.g. the blankslate gem RDoc
still refers to the builder README file), but give this guy a spin
around the block before I make an official release.
 
G

Guillaume Marcais

Le 21 f=E9vr. 06, =E0 21:55, Jim Weirich a =E9crit :
gem install blankslate --source http://onestepback.org/betagems

irb(main):004:0> require 'blankslate'
LoadError: No such file to load -- builder
from=20
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in=20
`require__'
from=20
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require'
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:163:in `activate'
from=20
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:23:in `require'
from (irb):4

Seems that the dependency on builder is still there.

Guillaume.
 
J

Jim Weirich

Guillaume said:
Le 21 f�vr. 06, � 21:55, Jim Weirich a �crit :


irb(main):004:0> require 'blankslate'
LoadError: No such file to load -- builder

Dang! Autorequire bit me again.

Ok, I think I fixed it. Give it another try.
 
J

Jim Weirich

MenTaLguY said:
ERROR: While executing gem ... (YAML::Error)
Invalid object explicitly tagged !ruby/Object: "requir"

Ahhh ... Interesting.

I've tracked this down to a corrupt compressed gem index on my beta
server. My home box wasn't getting it because it uses a unreleased
version of RubyGems that does incremental downloads of the individual
gem specs rather than grabbing the massive gem index all the time.

This might also explain an unrelated issue I was having with testing
RubyGems. I think this bug has made my day.

Now all I have to do is fix it.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] lazy.rb 0.2 1
[ANN] Futures and JRuby: The Omnibus Concurrency Library 0.2.1 3
[ANN] lazy.rb 7
[ANN] lazy.rb 0.1 0
[ANN] rs 0.1.2 0
lazy fibs 0
[ANN] XMLable 0.1.1 0
Calcul XOR : array , times. 3

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top