Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Is recursion allowed?

by clintp (Curate)
on Mar 25, 2002 at 21:29 UTC ( #154232=note: print w/replies, xml ) Need Help??


in reply to Is recursion allowed?
in thread Algorithm Pop Quiz: Sorting

Parrot allows you to push all of the string registers (pointers, actually) and integer registers onto their own private stack with pushs, pushi and restore them with pops and popi. (Numerics and PMC's with n/p respectively.) So you *can* write recursive subroutines after a fashion but effectively you make the entire register set local to each recursion:

set I0, 100 bsr FUNC print I0 # Gives 100 end FUNC: pushi set I0, 56 popi ret

local() for a particular registister can be emulated but it's a pain in the ass with something like:

set I0, 100 set I1, 200 set I6, 700 bsr FUNC # print I0 # 100, original value print I1 # 0, new value print I6 # 0, new value end # Local changes to I1 and I6 preserved # think of this as unlocal() :) FUNC: pushi # saves all integer registers set I0, 0 set I1, 0 set I6, 0 save I1 save I6 popi restore I6 restore I1 ret
The answer to your other question (asked in /msg) is that no, you can't peer down the stack or get the stack's depth at this time. However you can simulate peering into the stack just fine with the tools given.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://154232]
help
Chatterbox?
talexb admires the shimmering pool after an enjoyable hour-long All Hands meeting spent listening with one ear and reading Perlmonks with the other .. ear.
[talexb]: Used all my votes during that meeting .. been a while since I've done that. Now, back to work. Good localtime, monks!
[Corion]: talexb: You enjoyed the All Hands meeting in the pool?!
[Corion]: I understand "surfing" in the pool ;)
[talexb]: Corion I admired the pool .. I wasn't .. soaking in it. ;)
[talexb]: Plus, I've been awy from PM for about three weeks .. needed a bit of catch-up time.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2017-07-20 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (304 votes). Check out past polls.