martes, 1 de noviembre de 2011

Fastruby 0.0.15 released. Callcc and continuation objects!

Fastruby is a gem which allows to execute ruby code much faster than normal, currently in a state of transition between a spike and a usable gem, it is released when possible with incremental improvements.
The v0.0.15 release adds the support for continuation objects created using callcc function. To acchieve this, the implementation uses the non-lineal stack created on previous releases.
Also this release adds a few extra language support improvements such as method default arguments

Install

You can clone the repository at github:
git clone git://github.com/tario/fastruby.git
git checkout v0.0.15
Or install it using gem install:
gem install fastruby

New Features

Fixes

Examples of code being supported

Example of continuation calls, tail recursion


  1. require "fastruby"  
  2.   
  3. fastruby '  
  4. class X  
  5. def fact( n )  
  6.     a = callcc { |k| [ n, 1, k ] }  
  7.     n = a[0]  
  8.     f  = a[1]  
  9.     k  = a[2]  
  10.     if ( n == 0 ) then return f  
  11.     else  
  12.  k.call n-1, n*f, k  
  13.     end  
  14. end  
  15. end  
  16. '  
  17.   
  18. p X.new.fact(6) # 720  
Default Arguments
  1. require "fastruby"  
  2.   
  3. fastruby '  
  4. class X  
  5. def foo(a,b = a.reverse)  
  6.   a + b  
  7. end  
  8. end  
  9. '  
  10.   
  11. p X.new.foo("13"# 1331  
  12. p X.new.foo("xx""yy"# xxyy  
Passing proc objects as blocks
  1. require "fastruby"  
  2.   
  3. fastruby '  
  4. class X  
  5. def bar  
  6.   yield(1)  
  7.   yield(2)  
  8.   yield(3)  
  9. end  
  10.   
  11. def foo  
  12.   pr = proc do |x|  
  13.     p x  
  14.   end  
  15.   
  16.   bar(&pr) # passing proc as a block  
  17. end  
  18. end  
  19. '  
  20.   
  21. X.new.foo  

Receiving blocks as proc objects
  1. require "fastruby"  
  2.   
  3. fastruby '  
  4. class X  
  5. def bar(&pr)  
  6.   pr.call(1)  
  7.   pr.call(2)  
  8.   pr.call(3)  
  9. end  
  10.   
  11. def foo  
  12.   bar do |x|  
  13.     p x  
  14.   end  
  15. end  
  16. end  
  17. '  
  18.   
  19. X.new.foo  


No hay comentarios:

Publicar un comentario