Re: More feature requests, or is it syntax?
David Cuny wrote:
> > dic=dicAddItem(dic,thisWord)
> I almost always end up assigning a global variable in these instances, and
^^^^^^ AAARRGGGHHH!
>calling a procedure like:
> dicAddItem( thisWord )
Despite my AAARRRGGGHHH, yes, and I am sorely tempted to do so, but that
destroys everything, we're nearly back to the dark old days of
everything
global.
> Yeah, there are many times when I've written something using the form:
> variable = function( variable, value )
> when I've wondered if there were a better syntax for it. In PP, there are a nu
mber of tools, > similar to the += in C:
> a =+ 1 -- a = a + 1
> s =a "foo" -- s = append( s, "foo" )
> s =& "foo" -- s = s & "foo"
Dirty kludges. "Dirty" and "kludges" because they cater only for
particular
cases. If you really want that, then the syntax should be general, for
instance, if we accept +=, /= etc. which means:
<var 1> <operator>=<var 2>
is shorthand for:
<var 1> = <var 1><operator><var 2>
Then we should have:
s append="foo"
dic addWord="foo"
But that is horrible. The meaning is not evident at all. It is
a perversion of syntax (to me, syntax should be reader-friendly)
> dictionary = addDictionary( self, "foo" )
I had proposed that in an earlier post, not knowing that you had had
the same idea.
> or in the other direction:
> self = addDictionary( [dictionary], "foo" )
No, because you don't know what "self" is straight away, you have to
wait
until you encounter "[dictionary]"
> Even worse is the the proc_id version:
> dictionary = self( "addDictionary", { "foo" } )
That is horrible. I can't make head or tail of it. Terribly
anti-intuitive.
> I'd love to see a suggestion where this syntax was handled elegantly,
> without passing by reference. As it stands, the cure seems much worse than the
disease.
Well, let me think aloud... That would involve regularizing I/O. That
means that
there would be not procedures at all any longer, only functions. Do we
want that?
A function is really a shortcut, so that you can use its value without
having
to assign it to an intermediate variable. So functions ARE useful, but
they are
shortcuts for procedures. It seems the procedure is fundamental, and
that we
must allow for procedures which modify at least ONE parameter, just like
I/O procedures do. My idea of using square brackets [] instead of () was
silly, as it leads to ambiguities with sequences. Further, it was
completely
stupid because a procedure with () would do absolutely nothing, all of
its
parameters being passed by value! So, this leads to this simple
solution:
the first parameter of a function is passed by reference, all the rest
by
value. E.g.:
inc(i,10)
dicAdd(dic,"foo")
(I have a further idea, but I'll keep it under my hat for the time
being)
Frogguy (a.k.a. the other Jacques)
|
Not Categorized, Please Help
|
|