[REBOL] pseudo-globals? Re:(2)

2000-06-16 Thread Galt_Barber





r: make object! [
result: system/words/result
x: func [] [system/words/x result]
y: func [] [system/words/y result]
z: func [] [system/words/z result]
append: func [str] [system/words/append result str]
]

do bind [
x
y
z
append "stuff"
] in r 'self

>
>Regards,
>Gabriele.

Gabriele, you are one sharp cookie!
I always find myself saving your messages,
as they are chock full of superb thinking about Rebol.

This is a very good demonstration of using bind!

That's exactly the kind of thing I was looking for,
Bella!

-galt

p.s. Is there any way to do the same thing, even if
"result" were a local var and not global?

Also, I have 7 functions, and I would need to do this trick in each one.
Is it possible to create some other routine outside the 7 that sets up
the aliasing and then just refer to that function at the top of each of the 7?
It seems like this might be possible!
I can hide the unnecessary bits and without Global vars and so recursion is no
concern ?
Astounding.





[REBOL] pseudo-globals? Re:(2)

2000-06-16 Thread Al . Bri

> set 'Dialect func [Dialect [block!]] [reduce bind Dialect 'f1]

Feel free to substitute 'do for 'reduce if you prefer one result to a
multiplicity of results.

Andrew Martin
Many to Many...
ICQ: 26227169
http://members.xoom.com/AndrewMartin/
-><-




[REBOL] pseudo-globals? Re:(2)

2000-06-15 Thread Galt_Barber




I asked if anybody knew clever tricks to avoid passing
the same paramters over and over and over.

Allen reminded me,
I had forgotten about the syntax of system/words/varname.

Thanks, Allen K!

===

Just for an experiment, I made a copy of the source file in question
and used that to butcher it about a bit until I had some interesting results.

I am creating several functions, one for each of the 7 tenses in Irish.
Each does similar things and calls similar functions to change
the root word until it is fully conjugated.

I noticed that when I had condensed it down earlier, I had gotten to
a bunch of lines that looked like this:

somethinga result
somethingb result
if firstperson? somethingc result

etc.

So, I went back and I looked real hard at the alternatives.
I wanted the Rebol code to look as much like english as possible,
in the sense that the routine for each tense would be able to
be followed by someone interested in the Irish rather than
in programming, it should look almost like a (normal-)human readable set of
steps for conjugating any tense of an irish verb.

I was willing to hide the complexity in some functions,
as long as each function was ultimately a simple idea that
the language user would recognize.
e.g. "lenition" is a process that in modern standard adds an  'h' after
allowable consonants.  So I hide the testing of lenitable? and
so forth and just show Lenite Result.  e.g. ball lenited becomes bhall.

Well, I wanted to get rid of "result", and the only way I could figure it out
was to just make the darn thing global, now called "conj".
 Then I found that wasn't so bad
after all!  the code was a lot shorter and cleaner.  There was only
one place where you could effectively cheat and get the result
from calling another tense, and I figured I could deal with that if I had to,
by saving the 'person and restoring after the call.

It worked extremely well.  The seven main tense functions and the assorted
helpers now just use a bloody global variable, and the thing is ridiculously
simplified.  In the same spirit, the 'person doesn't change during a run
of the conjugation, so I made it also global and used by the main 7
and their helpers.   I basically had originally had 3 parameters and 2 local
variables defined at the head of each main function before.  Now there are none.
I used to have some lines of subtle tricks at the top of each of the 7 main and
a return line at the bottom, which certainly would distract the non-technical
person, so I yanked them out, too.

To make a long story shorter, I basically scrapped all the usual way of
paramaterizing
everything - and felt like I was doing "non-functional" programming, almost.
Back to my earliest days of basic without sub routines or parameters, almost.

I thought that the code would be a mess, but in fact it's shorter and more
comprehensible both to myself and to anyone else now.  Weird.

And although I now have to be careful about calling it recursively
and be more careful about stepping on the global value, it seems
like it may be worth it.  I am never really going to call these functions
recursively in a serious fashion.  I have one case where the Imperative
is constructed by calling other tenses, but it only goes one level deeper
and comes back.  There's no indefinite levels of recursion or anything like
that.

I feel like I am regressing here.  Anybody seen GOTO lately?

In fact, if it were possible to write a source code analyzer that could
warn you of potential problems, you might be able to let it tell
about the few issues there really are with clobbered variables
and fix them, rather than adopting the typical generic approach which is so
wasteful
of the programmer's and the computer's time.

I will include just one of the tenses here for comparison:

"sinn" means "we" in Irish
"fear" stands for the autonomous case, like in english "something was done" by
who?, not specified
"áil" is a special ending to be dealt with, and so is "éigh"

= original, before tried to condense it 

FutureTense: func [
 root[string!]
 person  [integer!]
 plural? [logic!]
 /local
 result
][

 result: lowercase copy root

 if matchtail result "áil"
  [remove skip tail result -2]

 if matchtail result "éigh"
  [remove/part skip tail result -2 2]

 append result "f"

 either (= 1 person) and (plural?) [
  if broadending? result [broaden result]
  append result "imid"
  ;-- handle 2nd Conj.
  replace result "ighf" "eó"
  replace result "aeó" "ó"
 ][
  either <> 0 person [
   if broadending? result [broaden result]
   append result reduce ["idh " make-person person plural?]
   ;-- handle 2nd Conj.
   replace result "ighf" "eó"
   replace result "aeó" "ó"
  ][
   if narrowending? result [narrow result]
   append result "ar"
   ;-- handle 2nd Conj.
   replace result "ighfe" "eóf"
   replace result "aeó" "ó"
  ]
 ]

 return result
]



=  before, after I had already worked alot to condense it 

FutureTense:

[REBOL] pseudo-globals? Re:(2)

2000-06-15 Thread Galt_Barber




Thanks, Thomas J, I am looking over your globalizer code now!!