|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: 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... ;) |
|
|
|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
|
_________________ CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;) |
|
|
|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: 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... ;) |
|
|
|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: 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... ;) |
|
|
|
alluran Adept
Joined: 14 Sep 2005 Posts: 223 Location: Sydney, Australia
|
Posted: Thu Jan 18, 2007 4:00 pm |
Nice Fix For It, And I Thought I'd Tried Virtually Everything ;)
|
|
_________________ The Drake Forestseer |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Jan 18, 2007 8:51 pm |
Thanks for the extra info on this. I've added it to the bug list.
|
|
|
|
|
|