Path: news.daimi.aau.dk!news.uni-c.dk!sunic!news.tele.fi!news.csc.fi!news.eunet.fi!EU.net!howland.reston.ans.net!darwin.sura.net!wvnvms!marshall.wvnet.edu!marshall.edu!hathawa2 Newsgroups: comp.lang.eiffel,comp.object,comp.lang.modula3,comp.lang.sather,comp.lang.beta Subject: Re: Cows, Hogs & Farms Message-ID: <1995Jan10.211607@hobbit> From: hathawa2@marshall.edu (Mark S. Hathaway) Date: 10 Jan 95 21:16:07 EDT References: <3e07c4$sup@muss.cis.McMaster.CA> <1995Jan5.183534.10065@schbbs.mot.com> <1995Jan10.180233.23224@inca.comlab.ox.ac.uk> Organization: Marshall University Nntp-Posting-Host: frodo.marshall.edu Lines: 64 Xref: news.daimi.aau.dk comp.lang.eiffel:7145 comp.object:23653 comp.lang.modula3:3321 comp.lang.sather:1408 comp.lang.beta:212 > In article <1995Jan10.180233.23224@inca.comlab.ox.ac.uk>, > lady0065@sable.ox.ac.uk (David J Hopwood) writes: >> In article <1995Jan5.183534.10065@schbbs.mot.com>, >> David L. Shang wrote: >>> In article <3e07c4$sup@muss.cis.McMaster.CA> >>> u9442202@muss.cis.McMaster.CA (E.H. Schnetter) writes: >>> OK, here is an example in Sather. > [example using type-cases snipped] >>What you presented here is "Invaraince + Runtime Type Check", not a >>covariance. >> >>At a hogsty, if there is a plate saying "please feed me any plant", what >>will happen? The sty will be full of rotten food that the hog does not eat. >> >>The plate should say "please feed me corn only". That is, the eat interface >>should tell its feeder the right food (if we suppose that a hog eat corn >>only). Why should a plate say "please feed me corn only"? Since when is that relevant? It's the HOG which favors CORN. The hog is a herbivore which eats and favors corn. A farmer (presumably) feeds (read as offers) something (usually corn) to the hog. You can say the hog has a method eat(), but that doesn't explain the states which are needed for it to decide when and what and how much to eat(). And, when the hog sees something in its trough and it appears to be corn and the hog is hungry (nearly always) the hog still might not eat if it senses there's something contaminating the food. Even the American congressman/woman won't feed at the gov't. trough if it's not something his constituents want. :-) I favor the declaration of HOG separate from its foods. There might be a hog in some part of the world which doesn't eat corn. Maybe the favorite food of HOG will depend more upon what's available than we're imagining. If a hog will eat something else then the class with CORN will be wrong. A more generic HOG with a derived HOG_liking_CORN or a HOG with an attribute ( attr favorite_food is plant(corn) ) would be more enduring and correct. > try and eat have different semantics, in that they make different guarantees > about whether the call will succeed. Most languages do not allow try and eat > to be declared differently (ie. they have no equivalent to 'partial'). Can't "try" be easily achieved with... procedure freds_life is begin if food_available AND hungry AND ( food = CORN ) then fred.eat(food); else #OUT.write "Yuck, get this " + string(food) + " outta here!" + nl; end; end freds_life; I can't see HOG having a method TRY. That makes no sense. Mark S. Hathaway