home .. forth .. colorforth mail list archive ..

Re: [colorforth] explicit vs. implicit


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 18 August 2004 02:57 am, stephen white wrote:
> On 18/08/2004, at 4:23 AM, Mark Slicker wrote:
> > + * dup +
> >
> > I get:
> >
> >        ____+_____
> >       /          \
> >      *            *
> >    /   \        /   \
> >   x     +      x     +
> >       /   \        /   \
> >      y     z      y     z
>
> Aren't you only DUP'ing the result so far?

The nice thing about a functional programming language is that there is 
absolutely *zero* distinction between 3+4, 7, and x+y, where x=2 and 
y=5.  This is mandated by the principle of referencial (referential?) 
transparency.

Well, Forth isn't exactly a pure functional language.  But even so, 
DUPing the top of stack has the effect of computing the same function 
with the same arguments twice -- in effect, replicating the entire 
dataflow through the function tree as if it were a unique branch.

Therefore, by the principle of referential transparency, Mark's example 
still holds.

> If you DUP then change the value of z before +'ing, you would get the
> same result as it's not really two trees being evaluated...

DUPing replicates the precise state of the dataflow -- changing z after 
the DUP creates a new dataflow.  Remember: changing z occurs after the 
DUP has already been completed.

- --
Samuel A. Falvo II
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBIy8GvwDm/l0jx/IRAnNrAKCFwAQSi5AB3VMw36bWKi1PTSm4YQCggcfA
h8+9vi3TkFHMEmnZKvNothE=
=zpio
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com