> -----Original Message-----
> From: Richard Biener <rguent...@suse.de>
> Sent: Friday, January 10, 2025 02:43
> To: Robert Dubner <rdub...@symas.com>
> Cc: jklow...@symas.com; Joseph Myers <josmy...@redhat.com>; gcc-
> patc...@gcc.gnu.org
> Subject: RE: [PATCH] COBOL 3/8 gen: GENERIC interface
> 
> Btw, is recursion allowed?
> 
>   f = 1
>   fact.
>   f = f * n
>   n = n - 1
>   if n != 0 perform fact
>   end-fact.
> 
> or something like this to compute n!

I couldn't resist, especially after I made the assertion that it would
work.  I needed to make sure it actually *would* work.

        identification      division.
        program-id.         prog.
        data                division.
        working-storage     section.
        77 n pic   9 comp-5.
        77 f pic 999 comp-5.
        procedure           division.
        move 6 to n
        move 1 to f
        display "compute " n " factorial".
        fact.
            compute f = f * n
            subtract 1 from n
            if n not equal to zero then 
                perform fact
            end-if.
        end-fact.
        display f.
        end program         prog.

$ ./test
compute 6 factorial
720

There. You have written a COBOL program.  Or if that's too shameful, then
you can say you inspired a COBOL program.

That little program is so charmingly on the nose, I am going to put it
into our test suite.

 
> --
> Richard Biener <rguent...@suse.de>
> SUSE Software Solutions Germany GmbH,
> Frankenstrasse 146, 90461 Nuernberg, Germany;
> GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG
Nuernberg)

Reply via email to