[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Mutual Recursion in Octave
From: |
Tomer Altman |
Subject: |
Mutual Recursion in Octave |
Date: |
Mon, 3 Nov 2003 08:15:08 +0000 (UTC) |
I was very pleased to find that Octave supports mutual recursion! This
is meant as merely a test of Octave's features, not as a supposed
efficient means of actually determining whether an integer quantity is
even or odd. Enjoy!
~Tomer
function [ bool ] = even ( num )
if ( num == 0 )
bool = true;
else
bool = odd ( num - 1 );
endif
endfunction
function [ bool ] = odd ( num )
if ( num == 0 )
bool = false;
else
bool = even ( num - 1 );
endif
endfunction
octave> even ( 5 )
ans = 0
octave> even ( 8 )
ans = 1
octave> odd ( 9 )
ans = 1
octave> odd ( 5 )
ans = 1
octave> odd ( 8 )
ans = 0
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Mutual Recursion in Octave,
Tomer Altman <=