Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
XP is just a number
 
PerlMonks  

Re^2: Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell

by audreyt (Hermit)
on Jan 14, 2006 at 12:18 UTC ( [id://523186]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell
in thread Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell

That's pretty nice... Here is a straight port from Ruby to Perl6:
sub evaluate ($expr) { my @stack; for $expr.split { @stack.push: do { when /^ -?\d* $/ { $_ } when <+ - * /> { my $right = @stack.pop; my $left = @stack.pop; defined($left & $right) or fail "Stack underflow"; $left.$_: $right; } fail "Invalid token: $_"; } } @stack == 1 or fail "Invalid stack: @stack"; @stack[0]; }
  • Comment on Re^2: Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://523186]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.