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 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b50bc6538a649497 X-Google-Attributes: gid103376,public From: John English Subject: Re: if statements Date: 2000/11/08 Message-ID: <3A094717.AAF0EB30@bton.ac.uk>#1/1 X-Deja-AN: 691185964 Content-Transfer-Encoding: 7bit References: <3A02CED4.520C2768@brighton.ac.uk> <3A078B6F.D34B024B@erols.com> <8mTN5.7821$pq3.603668@news.flash.net> <3A0824BB.14ACCA12@bton.ac.uk> <4x5O5.8364$pq3.657453@news.flash.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: news@bton.ac.uk X-Trace: saturn.bton.ac.uk 973686575 11276 193.62.183.204 (8 Nov 2000 12:29:35 GMT) Organization: University of Brighton Mime-Version: 1.0 NNTP-Posting-Date: 8 Nov 2000 12:29:35 GMT Newsgroups: comp.lang.ada Date: 2000-11-08T12:29:35+00:00 List-Id: Ken Garlington wrote: > > "John English" wrote in message > news:3A0824BB.14ACCA12@bton.ac.uk... > : Ken Garlington wrote: > : > Personally, I would have gone with something more along the lines of > : > > : > generic > : > type Value is private; > : > with function ">"(A, B : Value) return Boolean is <>; > : > procedure Homework_Assignment(A, B : in out Value); > : > > : > -- Exchange is defined in the Ada Reference Manual > : > with Exchange; > : > procedure Homework_Assignment(A, B : in out Value) is > : > procedure Swap is new Exchange(Value); > : > begin > : > if A > B then > : > Swap(A,B); > : > end if; > : > end Homework_Assignment; > : > > : > Can't you imagine how pleased the instructor will be to find out that > the > : > student has already mastered generics? > : > : Unfortunately this sort of question gets marked by an automated > : system, so the robotic instructor in question will, I'm afraid, > : be deeply unimpressed. ;-) > > Would it mark it as correct? If the original question was > > "Exercise 4.1: Write an if statement which will swap the values of > variables A and B if necessary so that the smaller value ends up in > A and the larger value ends up in B." > > I actually think my solution is a more excruciatingly correct answer, > compared to the "obvious" solution. In particular, the types of the > variables are not specified, so the solution shouldn't assume one - right? The robot embeds the submitted solution in a skeletal test program and runs it against a set of test data. The test program happens to declare A, B and T as Integer, but that's irrelevant (any non-limited type would do as well). The only problem with your solution is that the question asks for a bare statement; your solution would be embedded inside a block, so it would fail to compile without some extra work... ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk -----------------------------------------------------------------