Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 imbibing at the Monastery: (4)
As of 2015-07-06 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls