[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: orthogonality and generalized references (was Re: Zen of Python)

As an opportunity to "contemplate," Guy proposes contrasting the subtly
different behavior, in Icon, of
  /dict["foo"] := \dict["bar"]
  dict["foo"] := \dict["bar"]

I'd like to take it a step farther---as an opportunity to demonstrate
the regular and powerful mechanisms of Icon.  I'll do so by translating
each into Icon-like pseudo-code that lacks goal direction.  I say
Icon-like because there's no way to capture an l-value in Icon, so I'll
have to fake it.  (I'll also fake the "is null" test since that's what
we're talking about.)

 dict["foo"] :=  dict["bar"]      dict["foo"] :=  dict["bar"]

 dict["foo"] := \dict["bar"]      tmp := dict["bar"]
                                  if tmp is not null then
                                     dict["foo"] := tmp

/dict["foo"] := \dict["bar"]      lval := lvalueOf(dict["foo"])
                                  if rvalueOf(lval) is null then
                                     tmp := dict["bar"]
                                     if tmp is not null then
                                        rvalueOf(lval) := tmp

Is the left column clearer than the right column?  I think so, but then
I'm fluent in Icon.  Is it possible to write incomprehensible GD code?
Absolutely.  It's a balancing act, but I do know that I miss this kind
of GD construct in all other languages.  Could I construct these kinds
of control flow out of continuations?  Undoubtedly, but would it be as
clear and as regular as what Icon supports?  I doubt it.

On the other hand, I was able to cheat in the examples above because I
knew that none of the operands could produce more than one value
(whether null or not).  This fact allowed me to simplify the code on the
right a fair bit.  A more complicated example to contemplate would be
the following (useless) example.
   /dict["foo"] := \!dict

(In Icon the '!' operator produces the elements of a structure.  In the
case of a dictionary, it's the values, not the keys.)


-----Original Message-----
From: Guy Steele - Sun Microsystems Labs [mailto:Guy.Steele@sun.com] 
Sent: Tuesday, May 28, 2002 1:47 PM
To: Guy.Steele@sun.com; kragen@pobox.com; ll1-discuss@ai.mit.edu; Todd
Subject: RE: orthogonality and generalized references (was Re: Zen of

   Date: Tue, 28 May 2002 13:14:08 -0700
   From: "Todd Proebsting" <toddpro@microsoft.com>

   Guy, you and I are both right, I believe.  My example is correct, but
   description is incorrect.
   My example sets the value of dict["foo"] to 42 iff dict["foo"] was
   as I wanted it to.  My description of / is, however, backwards as you
   point out.  (I.e., the / computes the l-value iff the r-value *is*

And I was less than clear: I had included the example

  \dict["foo"] := 42
not as a proposed replacement for your example

  /dict["foo"] := 42

but as a contrasting example to illustrate the differing
behavior of "\" as opposed to "/".

Just for fun, we can contemplate the meaning of

  /dict["foo"] := \dict["bar"]

and how it subtly differs from

  dict["foo"] := \dict["bar"]