[comp.lang.icon] variables

gudeman@ARIZONA.EDU ("David Gudeman") (12/22/87)

   Date: Mon, 21 Dec 87 16:29:03 CST
   From: goer%sophist@gargoyle.uchicago.edu (Richard Goerwitz)
   ...
   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

Offhand I would say that this is not a problem in concept or in
implementation, but it might cause problems with efficiency.  We get a
_lot_ of suggestions for additions to Icon, and many of them are
interesting and/or useful.  I would classify your suggestion as both.

Obviously we cannot implement every useful suggestion, (or even most),
since Icon is already a large language (maybe too large), and because
it has a large user community that expects continuity between
versions.  However Icon is also a vehicle for research into
programming languages, and we are always interested in how users feel
about Icon and where they feel it needs improvement.

For a more direct answer to your question: I doubt very much that such
a feature will appear in the near future, as current research is
moving in other directions.  I like to think of our research as a
traversal through a hugely branching tree of possible programming
languages, searching for the Perfect Programming Language.  It's not
at all clear that the tree is finite.

					David Gudeman

					    Department of Computer Science
gudeman@arizona.edu			    Gould-Simpson Science Building
{allegra,cmcl2,ihnp4,noao}!arizona!gudeman  The University of Arizona
602-621-2858				    Tucson, AZ 85721

nowlin@ihuxy.UUCP (12/23/87)

> 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.