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,341730abd589d6e9 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: string operations Date: 2000/11/19 Message-ID: <8v90vm$j5f$1@nnrp1.deja.com>#1/1 X-Deja-AN: 695443675 References: <3A16A4D5.CE941970@t-online.de> X-Http-Proxy: 1.0 x52.deja.com:80 (Squid/1.1.22) for client 205.232.38.240 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Sun Nov 19 17:00:40 2000 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; I) Date: 2000-11-19T00:00:00+00:00 List-Id: In article <3A16A4D5.CE941970@t-online.de>, Margit Gut wrote: > Hi, > > my name is Margit and I am new here. I just start to learn ADA and I > have some problems in understandig what I am doing. > > I try to read a string from the keyboard and then I want to write a > recursiv function to turn the characters from the end to the beginning., This assignment has nothing to do with Ada specifically. The requirement for a recursive solution is the DOMINANT component of the assignment. You need to formulate an appropriate recursive approach completely independent of the language in which you will write, and you have not got that far, so your attempts to turn your thinking into Ada are very premature. Here are some hints: 1. Your solution must be able to work for arbitrary length input, so any constant like 255 is immediately wrong. 2. You need to think in terms of reading individual characters Learning to formulate recursive solutions to problems is a very challenging problem for many students, and I would say that many professional programmers have never learned this approach. One valuable excercise I have found is to write a reasonably complex program with no assignments at all. Here is my favorite example of recursion, to output an integer without worrying about its size: with Text_IO; use Text_IO; procedure Print_Nat (N : Natural) is begin if N >= 10 then Print_Nat (N / 10); end if; Put (Character'Val (N mod 10 + Character'Pos ('0'))); end Print_Nat; I like this example since it is not simple tail recursion like the factorial example, and it is in fact very hard work to turn this into a loop without imposing some arbitrary limit on the length. Note that this algorithm would work fine in a language that had arbitrary precision integers. Sent via Deja.com http://www.deja.com/ Before you buy.