Christopher Dicely wrote:
I'm a complete newbie trying to get a handle on Mozart/Oz (running on Windows XP Home, if that matters), so I've been trying some basic little programs to get a feel of it; one I tried to do was a fairly common kind of thing -- writing a program that outputs its command line arguments, reversed (both in reverse order of the arguments, and reversing the letters of each argument). If I do this:

functor
import
   Application
   System
define
for X in {List.reverse {Record.toList {Application.getGuiArgs plain}}.1} do
      {System.printInfo {List.reverse X}#" "}
   end
   {Application.exit 0}
end

Your program is wrong! It should not work at all, in fact. If you check the documentation, you will see that {Application.getGuiArgs plain} returns a *list* of strings, while Record.toList converts a *record* to a *list*. Your program seems to work fine because Oz' lists are records.

Let us analyse your program on an example. Assume that you call your program followed by "hello world". {Application.getGuiArgs plain} will thus return ["hello" "world"], which is the same as the record '|'("hello" '|'("world" nil)). Applying Record.toList will therefore return ["hello" '|'("world" nil)]. You then select the fist element with ".1", and reverse it. So the loop is done on the string "olleh", which happens to be a list.

The fix is easy: {Application.getArgs plain} returns the list of the arguments. Simply reverse it, and traverse it.

functor
import
   Application System
define
   for Arg in {Reverse {Application.getArgs plain}} do
      {System.printInfo {Reverse Arg}#" "}
   end
   {System.showInfo ""}
   {Application.exit 0}
end


Cheers,
raph

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to