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:
New Features
Examples of code being supported
Example of continuation calls, tail recursion
You can clone the repository at github:
git clone git://github.com/tario/fastruby.gitOr install it using gem install:
git checkout v0.0.15
gem install fastruby
New Features
- Continuation calls, non-local gotos
- Support for default method arguments
- Support for passing proc as block on method call
- Support for receiving block as proc object
Fixes
- Internal fix to support unlimited number of arguments on methods when called from normal ruby
- Minor fixes to splat arguments on blocks
- Removed yield_signature (inference of yield arguments) since this is not longer applicable
Example of continuation calls, tail recursion
- require "fastruby"
- fastruby '
- class X
- def fact( n )
- a = callcc { |k| [ n, 1, k ] }
- n = a[0]
- f = a[1]
- k = a[2]
- if ( n == 0 ) then return f
- else
- k.call n-1, n*f, k
- end
- end
- end
- '
- p X.new.fact(6) # 720
Default Arguments
- require "fastruby"
- fastruby '
- class X
- def foo(a,b = a.reverse)
- a + b
- end
- end
- '
- p X.new.foo("13") # 1331
- p X.new.foo("xx", "yy") # xxyy
Passing proc objects as blocks
- require "fastruby"
- fastruby '
- class X
- def bar
- yield(1)
- yield(2)
- yield(3)
- end
- def foo
- pr = proc do |x|
- p x
- end
- bar(&pr) # passing proc as a block
- end
- end
- '
- X.new.foo
Receiving blocks as proc objects
- require "fastruby"
- fastruby '
- class X
- def bar(&pr)
- pr.call(1)
- pr.call(2)
- pr.call(3)
- end
- def foo
- bar do |x|
- p x
- end
- end
- end
- '
- X.new.foo
No hay comentarios:
Publicar un comentario