From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3e08c98d7ce85399 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: Eight Queens problem (was Re: Kindness) Date: 1999/09/08 Message-ID: <7r4edb$gg2$1@nnrp1.deja.com>#1/1 X-Deja-AN: 522317378 References: <37CC6844.AB898EEE@rational.com> <37CE93CD.799A225A@pwfl.com> <37CF0FE0.2B299477@acenet.com.au> <37CFF7DC.CFF9717C@pwfl.com> <1999Sep3.125818.1@eisner> <37D02CC0.BEF1BC69@mitre.org> <7r1c4c$9an$1@nnrp1.deja.com> <7r2fc6$1sc$1@nnrp1.deja.com> X-Http-Proxy: 1.0 x28.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Share what you know. Learn what you don't. X-Article-Creation-Date: Wed Sep 08 01:33:31 1999 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-09-08T00:00:00+00:00 List-Id: In article <7r2fc6$1sc$1@nnrp1.deja.com>, bourguet@my-deja.com wrote: > Do you want to say it is the canonical example of use or it is an as > good example: there is another way to solve the problem which usually > come first to mind? Nothing so complicated, just that, as factorial is typically used in a text book to illustrate recursion, 8Q is used to illustrate backtracking. I agree that simple tail recursion is a horrible example for motivating recursion. Here is the example I always use, with a little driver: with Text_IO; use Text_IO; procedure p is procedure Print_Int (I : Natural) is begin if I >= 10 then Print_Int (I / 10); end if; Put (Character'Val (Character'Pos ('0') + I mod 10)); end Print_Int; begin Print_Int (12435); end; The nice thing about this is that it does simply something which is annoyingly fiddly to do iteratively. In particular, you have to worry about the maximum number of digits which simply does not arise. The point is made even more strongly in a language which does not have nasty artificial limits on the size of integers as in C or Ada or Java :-) Robert Dewar Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.