On Tue, 2003-09-30 at 15:10, Louis Kruger wrote:
> 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
> 

This isn't really a issue with generators - you would have the
same problem without them, as in:

     (x<0) := &null
and
     (0>x) := &null

It's the fact that the < operator (as most do) produces an rvalue, not
the fact that a generator is involved.  What you're really wanting is
a redefinition of < to produce it's rhs before deferencing instead of
after dereferencing.  That's possible, but it's now a 'control regime'
(to steal a term from my dissertation in the dim, dark past) instead of
an operator - and more expensive.

However, I think you're close to something.  Consider:

    (x<0,x) := &null

which does work.  You can't apply the above to a generator because
there's no way to reference the same result of a generator in two
separate lexical positions, as you can with a simple variable name.
Even coexpressions can't help you here!  So, if *that* problem were
solvable, you'd have at least a reasonably compact solution: e.g.

    every (!L < 0, &lastGenValue) := &null

[to invent a (weird) keyword] that would be comparable to the
simple variable case and hence 'consistent'.  I think it would be
a nightmare to implement efficiently, however.  Perhaps it's just
better to hide the current ugliness in a procedure:

    fixL(L,&null)

    procedure fixL(L,v)
        every L[i := 1 to *L] < 0 do L[i] := v
        return L   # just to return something besides &null or failure.
    end

or, if you'd prefer something a bit more general (danger, untested
code!):

    fix(L,"<",0,&null)

    procedure fix(L,op,v,r)
        every op(L[i := 1 to *L], v) do L[i] := r
        return L
    end

(Incidently, the language 'Seque' [odd outgrowth of Icon research back
in the 70's], *might* have had the ability to do what you want more
cleanly...but my memory of Seque is *really* hazy these days.)

-- 
Steve Wampler <[EMAIL PROTECTED]>


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