Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: svn+ssh://svn.dotswitch.net/var/svn/dotswitch/projects/library/plugins/purl@2122 c432a1ab-ec09-0410-8e5f-fb625be92370
- Loading branch information
nanki
committed
Oct 28, 2008
1 parent
792f6e3
commit 3cbdf8d
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Purl | ||
module Features::Lambda | ||
class << self | ||
include ::Purl::Features::Limit | ||
|
||
def operators | ||
[ | ||
Op.new(:call, 1), | ||
Op.new(:times, 2), | ||
Op.new(:each, -1), | ||
] | ||
end | ||
|
||
def call(macro) | ||
Result.new(*macro.dispatch) | ||
end | ||
|
||
def times(macro, n) | ||
n = [@max_n, n].min | ||
Result.new(*(macro.dispatch * n)) | ||
end | ||
|
||
def each(*stack) | ||
n = [@max_n, stack.pop].min | ||
macro = stack.pop | ||
op = macro.dispatch | ||
|
||
stack.concat stack.slice!(-n, n).map{|v| [v, *op]}.flatten | ||
Result.new(*stack) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters