[comp.sys.amiga] ARexx and mg3 questions

kosma%human-torch@STC.LOCKHEED.COM (Monty Kosma) (07/07/90)

I don't know if this should be in c.s.a or c.s.a.tech, so I figure I'll
post it to c.s.a since the c.s.a.tech people tend to react more viciously
to stuff incorrectly posted there :-)

I just (finally!) got Arexx (v 1.06 now, upgrading when bill sends the
card) and have been starting to experiment with linking up mg3 and
AmigaTeX and all sorts of other editor goodies.  I've got a few quirks
that I've run into that I'd like some comments on from anybody out
there.  Most of these have to do with the ideas about quoting stuff,
an issue not abundantly clear to me right now.  Experimentation has
led me to the following set of questions (and I did RTFM but no real
help there, yet):

1.  In an Arexx script file, typing 
address 'mg'
    works fine, but typing
address mg
    does not.  

2.  Also, in an Arexx script file, typing 
'rexx-insert "hello"'
    works (inserts hello into the current mg buffer), but 
say 'rexx-insert "hello"'
    does not work; it merely echos 'rexx-insert "hello"' to the shell.

3.  From within mg, the command 
M-x rexx ^M "'rexx-insert' "hi-there""
    hangs mg completely.  (mg bug?  or should I have guessed that?)

4.  From within mg, the command
M-x rexx ^M 'rexx-insert "hello"' 
    gives error 47, arithmetic conversion error (trying to subtract insert
    from rexx); apparently rexx-insert not get correctly quoted, so
M-x rexx ^M ' 'rexx-insert "hello" ' '
    does nothing.  Absolutlely nothing.  Then
M-x rexx ^M ' "rexx-insert" "hello" ' 
    works!
 
5.  related to (4) above, what help would doing
C-u M-x rexx ...
    provide (ctrl-u is supposed to somehow quote the args, but unfortunately
    the mg docs could be clearer.

6.  finally, doing a 
M-x rexx-do-region
    on a region which includes the line
"address 'mg'"
    gives a code 3 return error (mg port locked).  I have a clue but
    would appreciate some more explanation.


Thanks!

monty
kosma@human-torch.lasc-research.lockheed.com

p.s. Mike, you really ought to put in a short example on how to use
the commands name-last-kbd-macro and insert-kbd-macro ...it took me
quite a bit of trial and error to figure them out :-)

Thanks again!

mwm@raven.pa.dec.com (Mike (Real Amigas have keyboard garages) Meyer) (07/07/90)

In article <9007061951.AA00834@human-torch.lockheed.com> kosma%human-torch@STC.LOCKHEED.COM (Monty Kosma) writes:

   I don't know if this should be in c.s.a or c.s.a.tech, so I figure I'll
   post it to c.s.a since the c.s.a.tech people tend to react more viciously
   to stuff incorrectly posted there :-)

Since Rexx is going to be bundled, and I'd like mg3 to be bundled :-), I
think c.s.a is right. Note: I've not got a running mg + rexx port
here, so the examples are untested.

   1.  In an Arexx script file, typing 
   address 'mg'
       works fine, but typing
   address mg
       does not.  

Address is slightly wierd, in that it expects a variable or a simple
expression. Address 'mg' is a string, and it uses the text you gave
it. The second is a variable, so you get it's value. Rexx gives all
variables a default value of upper(variable), so you did the same as
address 'MG'. If you really want to say "address mg", try "mg = 'mg'"
somewhere beforehand.

   2.  Also, in an Arexx script file, typing 
   'rexx-insert "hello"'
       works (inserts hello into the current mg buffer), but 
   say 'rexx-insert "hello"'
       does not work; it merely echos 'rexx-insert "hello"' to the shell.

The first is issued as a command to the host, which does what you say
it should do. The second uses the rexx command 'say' to print a string
to the console. mg doesn't fool with the standard IO streams for rexx.
For one thing, I couldn't decide what to do with them. Suggestions are
welcome.

   3.  From within mg, the command 
   M-x rexx ^M "'rexx-insert' "hi-there""
       hangs mg completely.  (mg bug?  or should I have guessed that?)

Actually, you might be hung in Rexx. You're issuing something that
doesn't parse to Rexx.. Remember all the rexx command does is passes
it's argument to rexx to be dealt with. So you need to double the
internal quotes to make them work, like so:

	M-x rexx C-m "'rexx-insert ""hi-there"""

However, it shouldn't hang in any case. I'll add that to the list of
things to look at before the next release (that's a long list, and a
long time....)


   4.  From within mg, the command
   M-x rexx ^M 'rexx-insert "hello"' 
       gives error 47, arithmetic conversion error (trying to subtract insert
       from rexx); apparently rexx-insert not get correctly quoted, so
   M-x rexx ^M ' 'rexx-insert "hello" ' '
       does nothing.  Absolutlely nothing.  Then
   M-x rexx ^M ' "rexx-insert" "hello" ' 
       works!

Yes, you failed to quote 'rexx-insert' correctly. All mg does is pass
the string across; rexx parses it (normally, see below). The second
example should generate an error inside of Rexx. Strange that it
doesn't. The last one worked because you got the quoting right. Rexx
parsed the "'"'s and saw "rexx-insert" "hello". It would have worked
equally well to say "'rexx-insert hello'".

Getting strings right is a pain, because the two systems come from
different places and have utterly unrelated conventions. For instance,
Rexx recognizes "'", but mg doesn't; mg knows '\', rexx doesn't, and
so on. I recommend doing the following:

1) Quote all commands to mg (a good stylistic practice anyway) with
single quotes.

2) To get the right number of arguments, use double-quotes inside of
that to surround each argument. Note that using double quotes causes
'\' to be magic; not using double quotes causes whitespace to
terminated arguments, and '\' isn't special.

3) Inside the double quotes, use '\' to quote characters. Using these
rules, what you're trying to do would be written in a script as:

	'rexx-insert "hello"'

Trying to pass this through Rexx as a string command means you've got
to get a second set of quotes inside of it. So you do something like:

	"'rexx-insert ""hello""'"

or maybe:

	'''rexx-insert "hello"'''

or, since you've got a single word as an argument,

	"'rexx-insert hello'"

   5.  related to (4) above, what help would doing
   C-u M-x rexx ...
       provide (ctrl-u is supposed to somehow quote the args, but unfortunately
       the mg docs could be clearer.

The doc's say "the rest of the string will be tokenized by rexx", and
that's what it means. The only difference between the two is that with
C-u, mg turns on the RXFF_TOKEN bit in the message it sends to rexx.
Without that bit on, the rexx macro invoked will have one argument,
the string after the command name. If the C-u is used, then rexx will
pre-parse that string into multiple arguments, ala a function call. In
have no idea what rexx will do if you hand it a string macro with the
RXFF_TOKEN bit turned on.

   6.  finally, doing a 
   M-x rexx-do-region
       on a region which includes the line
   "address 'mg'"
       gives a code 3 return error (mg port locked).  I have a clue but
       would appreciate some more explanation.

More details needed, like did you really quote the command in the
region you sent to rexx? If so, then you tried to issue a command to
Rexx, and it should have worked. If instead you tried to address mg
from the region and then issue a command - well, the port was locked.

The problem is that anytime you invoke rexx from inside of mg (as
opposed to running a program outside of mg), it lock's mg so nothing
else (including the user) can fool with that mg while the script is
doing it's thing. Part of what happens in this case is that mg creates
a new port for the locked script to use. Doing an "address 'mg'" from
there goes back to the public port, which is currently refusing
messages because it's running a macro for the user. Just leave out the
"address 'mg'", and things should work.

   p.s. Mike, you really ought to put in a short example on how to use
   the commands name-last-kbd-macro and insert-kbd-macro ...it took me
   quite a bit of trial and error to figure them out :-)

I know, I know, I know. I may do a real manual in the near future,
including a discussion on tailoring mg with mg-startup.  There's just
to much to do, and not enough time to do it in....

	<mike
--
Look at my hopes,					Mike Meyer
Look at my dreams.					mwm@relay.pa.dec.com
The currency we've spent,				decwrl!mwm
I love you. You pay my rent.

cmcmanis@stpeter.Eng.Sun.COM (Chuck McManis) (07/07/90)

In article <9007061951.AA00834@human-torch.lockheed.com> (Monty Kosma) writes:
->1.  In an Arexx script file, typing 
->address 'mg'
->    works fine, but typing
->address mg
->    does not.  

address mg causes rexx to attempt to resolve the variable 'mg' which
is not what you want, using the quotes passes the string 'mg' to the 
address command. You could have said :
	editor="mg"
	address editor
and that would do what you expect, setting the host environment to the
contents of the editor variable.

->2.  Also, in an Arexx script file, typing 
->'rexx-insert "hello"'
->    works (inserts hello into the current mg buffer), but 
->say 'rexx-insert "hello"'
->    does not work; it merely echos 'rexx-insert "hello"' to the shell.

You are asking two different things, REXX first trys to parse the 
first word of the command as a verb and execute it. If it cannot
parse it, it passes the command on to the host environment for processing.
The quote in front of the command bypasses REXX's attempt to parse
it and instead feeds it straight to the rexx host (in this case mg)
The line 'say foobar' is a REXX command to print the string foobar on
the REXX "console" which in this case happens to be the shell. Using
"say foobar" (in quotes) would cause the REXX to send a "say" command
to the rexx host.

->3.  From within mg, the command 
->M-x rexx ^M "'rexx-insert' "hi-there""
->    hangs mg completely.  (mg bug?  or should I have guessed that?)
->
->4.  From within mg, the command
->M-x rexx ^M 'rexx-insert "hello"' 
->    gives error 47, arithmetic conversion error (trying to subtract insert
->    from rexx); apparently rexx-insert not get correctly quoted, so
->M-x rexx ^M ' 'rexx-insert "hello" ' '
->    does nothing.  Absolutlely nothing.  Then
->M-x rexx ^M ' "rexx-insert" "hello" ' 
->    works!
 
Sounds like the parsing of the mg command line is something like
CMD-ARG	     := ' REXX-COMMAND ' 
REXX-COMMAND :=   VERB ARGUMENT
VERB 	     := " <mg rexx command> "
ARGUMENT     := " <string> "

Which isn't a bad way to parse it. 

->5.  related to (4) above, what help would doing
->C-u M-x rexx ...
->    provide (ctrl-u is supposed to somehow quote the args, but unfortunately
->    the mg docs could be clearer.

Did you try ? C-u REXX-COMMAND M-x rexx ^M


->6.  finally, doing a 
->M-x rexx-do-region
->    on a region which includes the line
->"address 'mg'"
->    gives a code 3 return error (mg port locked).  I have a clue but
->    would appreciate some more explanation.

I'm stumped on this one. You shouldn't have to do an "address" command
since when REXX starts it should be automatically attached to the mg
host environment, did it work without that line? It is possible that
you are already connected to the mg rexx-host and the address mg command
attempts to make another connection to it which fails. (only one 
rexx connection allowed.) 


--
--Chuck McManis						    Sun Microsystems
uucp: {anywhere}!sun!cmcmanis   BIX: <none>   Internet: cmcmanis@Eng.Sun.COM
These opinions are my own and no one elses, but you knew that didn't you.
"I tell you this parrot is bleeding deceased!"

riley@batcomputer.tn.cornell.edu (Daniel S. Riley) (07/08/90)

In article <9007061951.AA00834@human-torch.lockheed.com> (Monty Kosma) writes:
->1.  In an Arexx script file, typing 
->address 'mg'
->    works fine, but typing
->address mg
->    does not.  

and

In article <138524@sun.Eng.Sun.COM> cmcmanis@stpeter.Eng.Sun.COM (Chuck McManis) writes:
>address mg causes rexx to attempt to resolve the variable 'mg' which
>is not what you want, using the quotes passes the string 'mg' to the 
>address command. You could have said :
>	editor="mg"
>	address editor
>and that would do what you expect, setting the host environment to the
>contents of the editor variable.

Mike said essentially the same thing, but I don't think it's right.
"ADDRESS" is a special case which doesn't, by default, evaulate its
arguments.  I believe Colinshaw discusses this in his book--it makes 
the language slightly irregular, but it seemed to match naive users'
expectations better.  So, in the ARexx manual, we find:

"ADDRESS {string | symbol}.  The string or symbol *taken as a literal*,
specifies the new host address" (emphasis mine)

In other words, "address mg" doesn't work because ARexx converts 
anything that isn't quoted to uppercase, not because the unset variable 
'mg' evaluates to 'MG'.  "address 'mg'" works because the quoted "'mg'"
isn't converted to uppercase.  Chuck's example won't work unless you
use the "address value" form to force evaluation of the variable.

You can test this easily enough, by evaulating a few simple lines like
	"ed='mg'; address ed; say address()"
	ED
	"ed='mg'; address value ed; say address()"
	mg
See?

It seems very uncharacteristic for both Mike and Chuck to make a mistake
like this.  Do you guys have a different version of ARexx, did I miss
something, or are we just way out on the tails of some probability 
distribution today?

-Dan Riley (riley@tcgould.tn.cornell.edu, cornell!batcomputer!riley)
-Wilson Lab, Cornell University

p.s.  mg3a is great.

bjornk@bula.se (Bjorn Knutsson) (07/09/90)

In article <9007061951.AA00834@human-torch.lockheed.com> kosma%human-torch@STC.LOCKHEED.COM (Monty Kosma) writes:
>I don't know if this should be in c.s.a or c.s.a.tech, so I figure I'll
>post it to c.s.a since the c.s.a.tech people tend to react more viciously
>to stuff incorrectly posted there :-)

I think this counts as .tech-stuff, at least that's my opinion.

[stuff deleted]
>1.  In an Arexx script file, typing 
>address 'mg'
>    works fine, but typing
>address mg
>    does not.  

Well, you just ran into one of the most popular gotchas with ARexx. Compare
these two examples...

1> rx "say hello"
HELLO
1> rx "say 'hello'"
hello

...I think you realize what happens. MG3a wants a lower case "mg" as its
address. Not putting quotes around the name will convert the string to
uppercase, since ARexx will try to interpret it as a variable and an
undefined variable always returns its name converted to upper case.
If the variable hello in the example above had been set to anything,
it would have returned whatever the variable contained.

>2.  Also, in an Arexx script file, typing 
>'rexx-insert "hello"'
>    works (inserts hello into the current mg buffer), but 
>say 'rexx-insert "hello"'
>    does not work; it merely echos 'rexx-insert "hello"' to the shell.

Of course. What did you expect? Only the functions of function libraries
and the internal functions of ARexx returns data in that fashion. Function
hosts are limited to the 'rc' and 'result' strings. And if you want the
stuff in the 'result' string, you must remember to set options results
in the beginning of your program.

What you did in your example was to send a string to the say-function.

[more stuff deleted]
>6.  finally, doing a 
>M-x rexx-do-region
>    on a region which includes the line
>"address 'mg'"
>    gives a code 3 return error (mg port locked).  I have a clue but
>    would appreciate some more explanation.

I guess MG3a locks its port whil doing a rexx-do-region. That makes sense
since you probably don't want anyone to interfere.

>monty
>kosma@human-torch.lasc-research.lockheed.com

---
Bjorn Knutsson        / USENET: bjornk@bula.se or sunic!sics!bula!bjornk
Stangholmsbacken 44  /  Phone : +46-8-710 7223
S-127 40 SKARHOLMEN /     "Oh dear, I think you'll find reality's on the
S W E D E N        /       blink again."  -- Marvin The Paranoid Android

new@udel.EDU (Darren New) (07/10/90)

In article <138524@sun.Eng.Sun.COM> cmcmanis@stpeter.Eng.Sun.COM (Chuck McManis) writes:
>address mg causes rexx to attempt to resolve the variable 'mg' which
>is not what you want, using the quotes passes the string 'mg' to the 
>address command. You could have said :
>	editor="mg"
>	address editor
>and that would do what you expect, setting the host environment to the
>contents of the editor variable.

Actually, according to the documentation (pg 25), the ADDRESS command
does not attempt to resolve the value of the variable. However, in
parsing, the variable name has already been shifted to upper case.  The
original "address mg" didn't work because the port was named "mg" and
not "MG".  If you want to do what you did above, try

    editor = "mg"
    address value editor


I think I've been bitten by this a couple of times. Note that there does not
seem to be a way of using "ADDRESS VALUE" along with a command at the same
time, as the parser would have trouble figuring out where the expression
stops and where the command starts.         -- Darren

lynn@phx.mcd.mot.com (Lynn D. Newton) (07/10/90)

I'm sure that some of us MG-lovers are glad to see the sudden
appearance on the net of some discussion of problems with using
MG3, particularly in regard to ARexx. It's tricky.

First, let me say that I'm very grateful to have MG3 available,
and I know what an enormous task it has been for Mike Meyer and
others to get it as far along as it is.  As a freebie we all have
to be thankful for whatever support we can get.

That having been said, can somebody tell me why the following
lines at the end of my mg-startup do not work, i.e. the key
bindings are never actually executed. The binding of normal
control key sequences works fine. Furthermore (and this is the
mysterious part), if I do the bindings "by hand", i.e. M-x
global-set-key^M<fill in the prompts> and so forth, which is a
real drag, the bindings _are_ made. I thought at first maybe the
option to bind function keys was not compiled in, but the fact
that I can do them from the keyboard tells me that I _can_.
What's wrong?

;
; BIND FUNCTION KEYS - these aren't working!
;
global-set-key "\F12" rexx			; F1
global-set-key "\F13" goto-line			; F2
global-set-key "\F14" overwrite-mode		; F3
global-set-key "\F15" global-set-key		; F4
global-set-key "\F16" beginning-of-buffer	; F5
global-set-key "\F17" end-of-buffer		; F6
global-set-key "\F18" amiga-window-to-top	; F7
global-set-key "\F19" amiga-toggle-border	; F8
global-set-key "\F20" call-last-kbd-macro	; F9
global-set-key "\F21" amiga-iconify		; F10
global-set-key "\F22" rexx-do-region		; F11
--
=================================================================
Lynn D. Newton            | System Test
Motorola MCD, Tempe, AZ   | (Department of Heuristic Neology)
(602) 437-3739            | "The bug stops here!"
lynn@jazz.phx.mcd.mot.com |

davidm@uunet.UU.NET (David S. Masterson) (07/11/90)

In article <9007061951.AA00834@human-torch.lockheed.com> kosma%human-torch@STC.LOCKHEED.COM (Monty Kosma) writes:

   I just (finally!) got Arexx (v 1.06 now, upgrading when bill sends the
   card) and have been starting to experiment with linking up mg3 and
   AmigaTeX and all sorts of other editor goodies.

Is MG3 released (out of beta)?  I'd like to get it if it is.  Question is,
where?

Thanx
--
===================================================================
David Masterson					Consilium, Inc.
uunet!cimshop!davidm				Mt. View, CA  94043
===================================================================
"If someone thinks they know what I said, then I didn't say it!"

riley@batcomputer.tn.cornell.edu (Daniel S. Riley) (07/11/90)

In article <LYNN.90Jul10084234@jazz.phx.mcd.mot.com> lynn@phx.mcd.mot.com (Lynn D. Newton) writes:
>That having been said, can somebody tell me why the following
>lines at the end of my mg-startup do not work
[...]
>global-set-key "\F12" rexx			; F1
[...]
>global-set-key "\F21" amiga-iconify		; F10
>global-set-key "\F22" rexx-do-region		; F11

Function key numbering in mg-startup is a little strange--mg3a
changed the names of the function keys from mg2.

F1 through F10 are "\f8" through "\f17".  shift-F1 is "\f18", and
so on.  The definitions you have should define F5 through shift-F5.

I don't remember seeing this documented anywhere--I had to check the
source to figure it out.

-Dan Riley (riley@tcgould.tn.cornell.edu, cornell!batcomputer!riley)
-Wilson Lab, Cornell University

kosma%human-torch@stc.lockheed.com (Monty Kosma) (07/18/90)

thanks for all the help on Arexx...I think I've got it now.  I guess I was
thinking/hoping/wishing that it behaved more like lisp in handling function
return values and stuff like that.

monty