I have some routines where it references the same
string over and over and over.

e.g.

somefunc:  func [
   someparam [string!]
   /local
   result  ;  [string!]
][
 x result
 y result
 z result
 append result "Blah"
 { etc. ad nauseum }

 return result

]

And I noticed that I was using "result" as the first parameter
passed to nearly everything.

Well, your first thought is that maybe you ought to make
result just be a global variable.  But not only does it
go against one's training and experience, but
in fact I actually have a case where somefunc calls somefunc2,
a routine that does something similar, and that would mess
me up.

So, how do I have a sort of almost global variable in the sense that
I can set it and then have all these functions know about it without
having to pass the darn value all around to everyone of them?
It gets tedious and one hopes that an advanced language
like Rebol might have some tricks to cure this ailment.

It reminds me a little bit of execution-scope?  where the scope
is defined by the block where it is first defined (or  redefined)
and then any funcs called after that see the var bound to the
new value, but then when the original block that had redefined
it goes out of scope then the older original value is restored
automatically.

Can some clever use be made of bind and objects in some way?
Can new instances of the functions be made and the words
in the procedure bound to them?
e.g. bind x,y,z to this "result", or bind copies of them?

I thought already about creating an object which has a layer like
this:

r: make object! [
 parm1: result
 xx: x parm1
 yy: y parm1
 zz: z parm 1
 aappend: func[ str] [append parm1 str]
]

and then going like this
r
r/xx
r/yy
r/zz
r/aappend "stuff"

but then I thought that it's only slightly better, and still not ideal.
what would be really cool is a way to bind x, y, and z
so that I don't need any extra clutter, so my code would just be
x
y
z
append "stuff"

and all these operations would happen on "result"

Does anybody have any idea what the heck I am trying to get at?
I hate seeing oodles of functions where the same stupid parameter
is passed over and over and over and over up and down thru the
various levels, never changing, just getting passed again and again and again,
and sometimes not just one but several.  Ick.  This situation must
be very common.

When we speak in human languages, we
often introduce a subject or topic and then it's understood
that we are referring to that until we say otherwise.
Computers are very precise, but only through tedious programmer
effort.  The obvious stuff shouldn't have to be said, said, said, said.

?

-galt


Reply via email to