Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!nntp.club.cc.cmu.edu!goldenapple.srv.cs.cmu.edu!das-news2.harvard.edu!cam-news-feed3.bbnplanet.com!cam-news-hub1.bbnplanet.com!news.bbnplanet.com!news-xfer.netaxs.com!wdcpop.dra.net!news.dra.com!azure.xara.net!xara.net!peernews.ftech.net!telehouse1.frontier-networks.co.uk!basilisk.pdc.nhs.gov.uk!yama.mcc.ac.uk!io.salford.ac.uk!aber!bath.ac.uk!dcl-cs!srm
From: srm@comp.lancs.ac.uk (Mr.S.R.Monk)
Subject: Re: HELP:case statement in smalltalk?
Message-ID: <E7yEqz.C1y@comp.lancs.ac.uk>
Sender: usenet@comp.lancs.ac.uk
Nntp-Posting-Host: tina.comp.lancs.ac.uk
Organization: Computing Department, Lancaster University.
References: <5hdqt8$3ca@babyblue.cs.yale.edu> <5hee8l$rf0$1@news.nyu.edu>
Date: Tue, 1 Apr 1997 10:06:35 GMT
Lines: 18

About the neatest way of doing a Case statement (if you must) is to use a
Dictionary thus.

switch := (Dictionary new)
	at: #plus put: [:x :y | x + y];
	at: #minus put: [:x :y | x - y];
	at: #multiply put: [:x :y | x * y].

z := (switch at: operator) value: 2 value: 3.

So basically the values of your dictionary are blocks that you lookup
and pass values into to get a result.

Simon.

Simon Monk. Bluecrest Consultancy. srm@comp.lancs.ac.uk.
-- 
Simon
