Well, it works in that the MYN parameter is a NEWed variable that keeps state.
I agree the MYN* makes it into a real Factorial function rather than just
a function that calls itself recursively and always returns 1.

If you do NOT want the implicit NEW MYN that occurs by the standard, you can
pass a variable by using .VARNAME in the call. (of course, this doesn't work
if you are passing an expression) It's not tail-end recursion optimization,
because the subroutine stack still increases with each call, but it will use
the same variable, so you have some optimization possible.

David
> 
> OH NEVER MIND...I'm being stupid.
> 
> I meant to type
> 
> Q MYN*$$FACT(MYN-1)
> 
> but didn't.
> 
> Anyway, I didn't expect this to work, but apparently it does.
> 
> --- Greg Woodhouse <[EMAIL PROTECTED]> wrote:
> 
> > Even worse
> > 
> > 
> > >ZL ZZGBAD ZP
> > FACT(MYN)       ; ; 3/8/05 12:23pm
> >         Q:MYN'>0 1
> >         Q $$FACT(MYN-1)
> >         ;
> > FACT2(MYN)      ;
> >         N X
> >         S X=MYN
> >         Q:X'>0 1
> >         Q $$FACT(X-1)
> > 
> > >W $$FACT^ZZGBAD(5)
> > 1
> > >W $$FACT2^ZZGBAD(5)
> > 1
> > >
> > --- Greg Woodhouse <[EMAIL PROTECTED]> wrote:
> > 
> > > Sure.
> > > 
> > > 
> > > >ZL ZZGBAD ZP
> > > FACT(MYN)       ; ; 3/8/05 12:14pm
> > >         Q:MYN'>0 1
> > >         S VAL=$$FACT(MYN-1)
> > >         S MYN=0 ;MYN changed!
> > >         Q VAL
> > > 
> > > >W $$FACT^ZZGBAD(5)
> > > 1
> > > >
> > > 
> > > 
> > > --- Greg Kreis <[EMAIL PROTECTED]> wrote:
> > > 
> > > > I am not following your reasoning Greg.  Can you provide an
> > > example?
> > > > 
> > > > Greg Woodhouse wrote:
> > > > 
> > > > >Another thing to watch out for is recursive calls. With the
> > > scoping
> > > > >works in MUMPS it seems to me that the only safe option is to
> > copy
> > > > >parameter values into NEW variables (so that you have a separate
> > > > copy
> > > > >in each stack frame). Otherwise, things might not work as you
> > > > expect.
> > > > >
> > > > >--- Greg Woodhouse <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > >  
> > > > >
> > > > >>In fact, I recall creating a special lookup routine that called
> > > > ^DIC
> > > > >>--
> > > > >>except that I neglected to include the "I" flag for ignore
> > > special
> > > > >>lookup routine. Needless to say, the result was "interesting".
> > > > >>
> > > > >>--- Greg Kreis <[EMAIL PROTECTED]> wrote:
> > > > >>
> > > > >>    
> > > > >>
> > > > >>>It can happen with repeatedly performing a DO command to any
> > > > >>>location.  
> > > > >>>Anything that is putting new entries on the stack frame
> > without 
> > > > >>>eventually removing them.  The stack on DSM or Cache can
> > > probably
> > > > >>>handle 
> > > > >>>300+ entries, so it never overflows with legitimate logic. 
> > ;-)
> > > > >>>
> > > > >>>Greg Woodhouse wrote:
> > > > >>>
> > > > >>>      
> > > > >>>
> > > > >>>>It means there was an intepreter stack overflow. :-)
> > > > >>>>
> > > > >>>>Actually, I think you got into an infinite loop making
> > repeated
> > > > >>>>        
> > > > >>>>
> > > > >>>routine
> > > > >>>      
> > > > >>>
> > > > >>>>calls (each of which requires the allocation of a new stack
> > > > frame,
> > > > >>>>which contains such details as NEW variables and the return
> > > > >>>>        
> > > > >>>>
> > > > >>>address).
> > > > >>>      
> > > > >>>
> > > > >>>>--- "Naik, Chintan (EDS)" <[EMAIL PROTECTED]> wrote:
> > > > >>>>
> > > > >>>> 
> > > > >>>>
> > > > >>>>        
> > > > >>>>
> > > > >>>>>Anyone know what this error means?
> > > > >>>>>
> > > > >>>>>%DSM-E-STKOVR, Interpreter stack overflow
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>Thanks,
> > > > >>>>>
> > > > >>>>>Chintan Naik
> > > > >>>>>Health System Design & Development
> > > > >>>>>* (972)-796-2414 - (Plano - Tue, Wed, Thu)
> > > > >>>>>* (817)-798-0546 - (Dallas OIFO - Mon, Fri)
> > > > >>>>>*    Fax:   (972)-796-6181 
> > > > >>>>>* mailto:[EMAIL PROTECTED]
> > > > >>>>>
> > > > >>>>>To care for him who shall have borne the battle and for his
> > > > widow
> > > > >>>>>          
> > > > >>>>>
> > > > >>>and
> > > > >>>      
> > > > >>>
> > > > >>>>>his orphan... Abraham Lincoln
> > > > >>>>>
> > > > >>>>>Enrollment Systems Group... Where VA Health Care Begins!
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>-------------------------------------------------------
> > > > >>>>>SF email is sponsored by - The IT Product Guide
> > > > >>>>>Read honest & candid reviews on hundreds of IT Products from
> > > > real
> > > > >>>>>users.
> > > > >>>>>Discover which products truly live up to the hype. Start
> > > reading
> > > > >>>>>          
> > > > >>>>>
> > > > >>>now.
> > > > >>>      
> > > > >>>
> > > > >>>>>http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
> > > > >>>>>_______________________________________________
> > > > >>>>>Hardhats-members mailing list
> > > > >>>>>[email protected]
> > > >
> > >>>>>https://lists.sourceforge.net/lists/listinfo/hardhats-members
> > > > >>>>>
> > > > >>>>>   
> > > > >>>>>
> > > > >>>>>          
> > > > >>>>>
> > > > >>>>=====
> > > > >>>>A practical man is a man who practices the errors of his
> > > > >>>>        
> > > > >>>>
> > > > >>>forefathers. --Benjamin Disraeli
> > > > >>>      
> > > > >>>
> > > > >>>>====
> > > > >>>>Greg Woodhouse 
> > > > >>>>[EMAIL PROTECTED] 
> > > > >>>>[EMAIL PROTECTED] 
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>-------------------------------------------------------
> > > > >>>>SF email is sponsored by - The IT Product Guide
> > > > >>>>Read honest & candid reviews on hundreds of IT Products from
> > > real
> > > > >>>>        
> > > > >>>>
> > > > >>>users.
> > > > >>>      
> > > > >>>
> > > > >>>>Discover which products truly live up to the hype. Start
> > > reading
> > > > >>>>        
> > > > >>>>
> > > > >>>now.
> > > > >>>      
> > > > >>>
> > > > >>>>http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> > > > >>>>_______________________________________________
> > > > >>>>Hardhats-members mailing list
> > > > >>>>[email protected]
> > > > >>>>https://lists.sourceforge.net/lists/listinfo/hardhats-members
> > > > >>>>
> > > > >>>> 
> > > > >>>>
> > > > >>>>        
> > > > >>>>
> > > > >>=====
> > > > >>A practical man is a man who practices the errors of his
> > > > forefathers.
> > > > >>--Benjamin Disraeli
> > > > >>====
> > > > >>Greg Woodhouse 
> > > > >>[EMAIL PROTECTED] 
> > > > >>[EMAIL PROTECTED] 
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > > > >>-------------------------------------------------------
> > > > >>SF email is sponsored by - The IT Product Guide
> > > > >>Read honest & candid reviews on hundreds of IT Products from
> > real
> > > > >>users.
> > > > >>Discover which products truly live up to the hype. Start
> > reading
> > > > now.
> > > > >>http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> > > > >>_______________________________________________
> > > > >>Hardhats-members mailing list
> > > > >>[email protected]
> > > > >>https://lists.sourceforge.net/lists/listinfo/hardhats-members
> > > > >>
> > > > >>    
> > > > >>
> > > > >
> > > > >
> > > > >=====
> > > > >A practical man is a man who practices the errors of his
> > > > forefathers. --Benjamin Disraeli
> > > > >====
> > > > >Greg Woodhouse 
> > > > >[EMAIL PROTECTED] 
> > > > >[EMAIL PROTECTED] 
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >-------------------------------------------------------
> > > > >SF email is sponsored by - The IT Product Guide
> > > > >Read honest & candid reviews on hundreds of IT Products from
> > real
> > > > users.
> > > > >Discover which products truly live up to the hype. Start reading
> > > > now.
> > > > >http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> > > > >_______________________________________________
> > > > >Hardhats-members mailing list
> > > > >[email protected]
> > > > >https://lists.sourceforge.net/lists/listinfo/hardhats-members
> > > > >
> > > > >  
> > > > >
> > > > 
> > > 
> > > 
> > > =====
> > > A practical man is a man who practices the errors of his
> > forefathers.
> > > --Benjamin Disraeli
> > > ====
> > > Greg Woodhouse 
> > > [EMAIL PROTECTED] 
> > > [EMAIL PROTECTED] 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > -------------------------------------------------------
> > > SF email is sponsored by - The IT Product Guide
> > > Read honest & candid reviews on hundreds of IT Products from real
> > > users.
> > > Discover which products truly live up to the hype. Start reading
> > now.
> > > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> > > _______________________________________________
> > > Hardhats-members mailing list
> > > [email protected]
> > > https://lists.sourceforge.net/lists/listinfo/hardhats-members
> > > 
> > 
> > 
> > =====
> > A practical man is a man who practices the errors of his forefathers.
> > --Benjamin Disraeli
> > ====
> > Greg Woodhouse 
> > [EMAIL PROTECTED] 
> > [EMAIL PROTECTED] 
> > 
> > 
> > 
> > 
> > 
> > -------------------------------------------------------
> > SF email is sponsored by - The IT Product Guide
> > Read honest & candid reviews on hundreds of IT Products from real
> > users.
> > Discover which products truly live up to the hype. Start reading now.
> > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> > _______________________________________________
> > Hardhats-members mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/hardhats-members
> > 
> 
> 
> =====
> A practical man is a man who practices the errors of his forefathers. 
> --Benjamin Disraeli
> ====
> Greg Woodhouse 
> [EMAIL PROTECTED] 
> [EMAIL PROTECTED] 
> 
> 
> 
> 
> 
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Hardhats-members mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/hardhats-members
> 



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Hardhats-members mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hardhats-members

Reply via email to