Re: Perceptron in Euphoria
- Posted by Alfredo Brand <abrand at ALUMINA.COM.CO> Nov 29, 1998
- 697 views
------=_NextPart_000_0019_01BE1BD6.9E926C60 charset="iso-8859-1" -----Mensaje original----- De: Irv Mullins <irv at ELLIJAY.COM> Para: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU> Fecha: domingo 29 de noviembre de 1998 13:24 Asunto: Re: Perceptron in Euphoria >On Sun, 29 Nov 1998 00:33:02 -0500, Alfredo Brand <abrand at ALUMINA.COM.CO> wrote: > >>my first contibution to this list. >>If you think It, you can make it. >>After several days of programming I finally got It, >>enjoy it. > >Congratulations! You tackled some difficult areas: numeric input, >for example, and got them to work. No small feat. > >If I were using this in a programming class, I would use your >code to discuss several ideas: > >1. Is there an easier and shorter way to write the date displays? >2. Following up on Ralf's comment ("It's in Spanish!";), is there >an easy way to internationalize this program? >3. There is a lot of repetition of the tasks: > SetColors > SetPosition > puts(1,something) > Perhaps we could combine those into a one-liner? > >We can solve 1 and 2 with a single concept: The days never change. >There are always seven. Day[2] is (in Euphoria) always Monday/Lunes. >The months never change, month 1 is always January/Enero. >They are - umm...constant. >Why not put them into a list, and reference them by number? >What's more, if we put the list at the top of our program, it will >be easy for anyone to change the names of days and months into the >language of their choice. > >Doing this will also simplify our logic quite a bit. See below. > >Problem 3 is even more easily solved, resulting in shorter code. >See the Display() function below: > >-- Ingenieria de Sistemas III >-- Inteligencia Artificial >-- Profesor : Ricardo Chavarriaga >-- Alfredo Brand >-- albrand65 at hotmail.com >-- brand >-- Funciones >--- with modifications by Irv Mullins > >constant month = {"Enero","Febrero","Marzo","Abril", > "Mayo","Junio","Julio","Agosto", > "Septiembre","Octubre","Noviembre","Diciembre"} > >constant days = {"Dom","Lun","Mar","Mie","Jue","Vie","Sab"} > >global procedure Display(sequence coords, sequence colors, sequence text) > position(coords[1],coords[2]) > text_color(colors[2]) > bk_color(colors[1]) > puts(1,text) >end procedure > >global procedure fecha_hora() >sequence dt, colors, ampm >integer mo, da, yr, hr, min, sec > colors = {BLACK,WHITE} > Display({4,02},colors,"Inteligencia Artificial") > Display({5,02},colors,"Ingenieria de Sistemas") > for i = 1 to 3 do > Display({5,i+24},{BLACK,i+1},"I") -- trick > end for > Display({6,02},colors,"Alfredo Brand") > Display({7,02},colors,"Profesor") > Display({8,02},colors,"Ricardo Chavarriaga") > > dt = date() -- convert the date > yr = dt[1] mo = dt[2] da = dt[3] > hr = dt[4] min = dt[5] sec = dt[6] > if compare(dt[4..6],{12,0,0}) = 1 then -- anyone see an error here? > if hr > 12 then hr = hr - 12 end if > ampm = "pm" > else ampm = "am" > end if > > position(1,1) -- display the days of the week > for d = 1 to 7 do > if d = dt[7] then > text_color(BRIGHT_RED) > bk_color(RED) > else text_color(RED) > bk_color(BLACK) > end if > printf(1," %3s ",{days[d]}) > end for > > Display({1,40},{BLUE,YELLOW}, > sprintf(" %s %d, %d ",{month[mo],da,yr+1900})) > -- note: you cannot use "19%d",yr here! Why not? > Display({2,40},{BLUE,WHITE}, > sprintf(" %02d:%02d %s",{hr,min,ampm})) > >end procedure > >This is only a first attempt. No doubt there are easier ways to do >some of this. Any takers? >And does anyone not know why the year must be displayed as shown >above? > >Irv Thanks for checking the code, you made it short. well job with the function >global procedure Display(sequence coords, sequence colors, sequence text) > sprintf(" %s %d, %d ",{month[mo],da,yr+1900})) about this yr is two digits, that's why you plus 1900. printf(1," %d, 19%d",{dt[3],dt[1]}) It has the same effect. I made the changes you suggested to the code I'm sending. ------=_NextPart_000_0019_01BE1BD6.9E926C60 name="brand.e" Content-Transfer-Encoding: quoted-printable