Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Sat Dec 30, 2006 1:35 pm   

[1.24] Recursive functions causing hard crash
 
From the help
Quote:
#FU fact {%if(%1<=1,1,%1*@fact(%eval(%1-1)))}
creates a user defined function to compute the factorial of a number

#EVAL @fact(5)
will display 120 given the above definition

Works as described in zMUD
Hard crashes with an access violation in CMUD

So I guess #FU is a bit #FU when recursion is involved (hehe he he, geddit? sorry)

Was actually trying to get a hex2dec function created when things went awry.
Was something like
%if(len(%1)<2, 16*1, (16 * %rightback) + @hex2dec(%leftback(%1, 1))
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Sat Dec 30, 2006 6:48 pm   
 
lol, didn't even notice the same bug below
http://forums.zuggsoft.com/phpbb/viewtopic.php?t=26038

Might be a clearer example here anyway <shrug>
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Sun Dec 31, 2006 1:25 pm   
 
Found a workaround.

It's not recursive functions themselves that are messed up, but the syntax suggested by the help that seems to be tripping CMUD up.
If you use %eval(@function(val)) to recursively call a function then things work. If you just use @function(val) then things break.

So modifying the helpfile
Original: #FU fact {%if(%1<=1,1,%1*@fact(%eval(%1-1)))}
Modified: #FU fact {%if(%1<=1,1,%eval(%1*@fact(%1-1)))}

Fixes up the factorial example, and #say @fact(5) displays 120 correctly.

Hope that helps track things Zugg
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Jan 18, 2007 1:14 pm   
 
bump
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Thu Jan 18, 2007 4:00 pm   
 
Nice Fix For It, And I Thought I'd Tried Virtually Everything ;)
_________________
The Drake Forestseer
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Jan 18, 2007 8:51 pm   
 
Thanks for the extra info on this. I've added it to the bug list.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net