Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Adding 2 + 2 (stack machine,bug fix)

by ikegami (Patriarch)
on Apr 21, 2008 at 19:12 UTC ( [id://682004]=note: print w/replies, xml ) Need Help??


in reply to Re: Adding 2 + 2 (stack machine)
in thread Adding 2 + 2

The parent assumed the accumulator was initially zero. That's not likely in a real-life scenario, so this removes the assumption:
my @stack; my $acc = rand; sub PUSH() { push(@stack, $acc); } sub POP() { pop(@stack); } sub INC() { $acc++; } sub ADD() { $acc += POP; } sub SUB() { $acc -= POP; } PUSH; SUB; INC; INC; PUSH; ADD; print("$acc\n");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://682004]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2026-02-10 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    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.