I'm a bit of a newcomer to Icon/Unicon, but I'm finding it to be an interesting language with which to approach some kinds of tasks.

I've found that there's a natural to way to do things like clipping values of a list using the <:= style operators.

For example, you can set all the negative elements of a list to 0:

every !list <:= 0

But although these operators are nice when applicable, they don't solve the general problem of using a reference from a generator multiple times. For example I was writing an algorithm where I wanted to compare things to one value, and set them to something else. For example, the following would be a natural way to set every negative element in a list to &null, except it doesn't work.

every (!list<0) := &null

It doesn't work because this evaluates to 0:=null. It doesn't work even if it is turned around:

every (0>!list) := &null

because the !list has already been dereferenced before the assignment takes place.

For a while I couldn't think of any way do this directly, so usually I give up on being clever, and just do it the boring way:

every i:=1 to *list do if list[i]<0 then list[i]:=&null

The problem with this is that doesn't generalize to arbitrary generators that return variable references.

Finally, I came up with a hackish approach that does work:

every (tmp:=&null & !list<->tmp & tmp<0)

but it lacks in elegance, efficiency and readability.

So is there some better, general way to do multiple things with a reference returned from a generator before it has been dereferenced?

Louis



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to