Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

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


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
Node Status?
node history
Node Type: note [id://523186]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-11-26 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (163 votes), past polls