Path: utzoo!utgpu!water!watmath!clyde!rutgers!sdcsvax!ucbvax!ihuxy.UUCP!nowlin From: nowlin@ihuxy.UUCP Newsgroups: comp.lang.icon Subject: Re: variables Message-ID: <8712222141.AA19282@megaron.arizona.edu> Date: 22 Dec 87 21:06:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The ARPA Internet Lines: 67 > Seeing as variables are passed by value and not reference, it is difficult > to perform the same operation on a series of variables with any degree of > elegance or economy. I often end up doing things like > > a := doito(a) > b := doito(b) > c := doito(c) > etc... > > I wonder if it would eventually be possible to include some mechanism in > ICON for manipulating variables themselves (and not just their values). > > Or is there some basic problem with doing things this way...? > > -Richard Goerwitz It's easy to have doito() perform it's operation on a list of variables and return a new list with modified variables. I'd call that fairly elegant. You could call doito() with an already defined list: l1 := [a,b,c] l2 := doito(l1) or just pass the list of variables as a constant: l2 := doito([a,b,c]) or go even further and make doito() a generator: every i := doito([a,b,c]) do ... It sounds like what you want is procedures with side effects instead of procedures that act like functions, kind of like subroutines in FORTRAN. This is possible but the way that data structures like lists are normally operated on in Icon creates new copies of the list. The following procedure modifies the contents of a list and the modifications stay in effect in the main procedure. In order to avoid making a copy of the list during the processing you have to use subscripts. YECH! procedure main (args) dub(args) every write(!args) end procedure dub(lst) every i := 1 to *lst do lst[i] *:= 2 end The normal way I'd do this in Icon would be: procedure main (args) every write(dub(args)) end procedure dub(lst) every suspend !lst *:= 2 end This is elegant to me. Jerry Nowlin (...!ihnp4!ihuxy!nowlin) P.S. I tried to reply to the message about regular expressions last week but it didn't get out correctly. I have a grep written in Icon if anyone is interested.