Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Re: Recursive function won't compile

Reply
Thread Tools

Re: Recursive function won't compile

 
 
Robbie Hatley
Guest
Posts: n/a
 
      04-03-2008

"bc1891" wrote:

> #include <stdio.h>
> #include <stdlib.h>
>
> def RecursiveFact(n):
> if(n>1):
> return n*RecursiveFact(n-1)
> else:
> return 1
>
> fact = RecursiveFact(31)
> print fact
>
> fact = "End of program"
> print fact
>
> ......but yet it still gives the right answer. How is this possible?



No, no, no. Write that in Haskell instead, like this:


#Switch<C++RTTI>(ON)
#include <stdio.h> AND <stdlib.h>
#use FORTRAN_RUNTIME_MODULE but compile_as(Cobol)
#Incorporate{PascalInterpreter} but run_as(Haskell)
use strict;
use warnings;
sub RecursiveFact
{
my $n=shift;
if ($n > 1)
{
return $n * RecursiveFact($n-1);
}
else
{
return 1;
}
}
printf("%d\n",RecursiveFact($ARGV[0]));


Yep, that there Haskell program should solve these C++
problems you've been having with that Oberon program of yours,
by injecting a bit of Perlescence.


Or just write it in Fortran and be done with it:


/* This is a really lovely Fortran program. */
#include <stdio.h>
#include <stdlib.h>
int RecursiveFact (int n)
{
return n>1?n*RecursiveFact(n-1):1;
}
int main (int argc, char ** argv)
{
printf("%d", RecursiveFact(atoi(argv[1])));
return 0;
}


--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive function won't compile bc1891@googlemail.com Python 6 04-03-2008 03:09 AM
Recursive function won't compile bc1891@googlemail.com C Programming 5 04-03-2008 03:09 AM
Two recursive calls inside of a recursive function n00m C++ 12 03-13-2008 03:18 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
new java programmer with compile error and trouble writting a Recursive Function judith Java 4 10-26-2006 09:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57