Please can someone explain what I am doing wrong here?  The code below generates a graphical interface for a program that calculates rows of Pascal's triangle.  The output is directed to a text box.  It works fine when the row is displayed using {Show ...} but not when I try to display it using QTk.
(Q  When using Show for row 4 the output is [1 4 6 4 1] but when using it for row 11 it is 1|10|45|120|210|252|210|120|45|10|,,,|,,, Why is the format different and why is the second form incomplete?)
What is displayed using QTk seems partly to depend on the operating system.  On my Windows PC only rubbish is output to the graphics interface when the input value for the number of the row is less than 12.  On my Linux system, for an input value of 5 or less the output is in the form \x01\x03\x03\x01 (for an input of 4, say).  I know these are hex values; I would like them to be decimal (and of the form [1 3 3 1]).  For values greater than about 5 until values greater than 11, the output is the same sort of rubbish as the Windows version.  For input values over 11, the program fails on both systems with an error message.  In the case of Windows the message is as follows (and similarly for Linux).
 
%*************************** type error *************************
%**
%** Expected type: tickle
%** In statement:  {Tk.return 'catch'(v([123]) b([<O: Class.new> insert(,,,)]) v([125])) <P/2 TkStringToInt> _<optimized>}
%**
%** Call Stack:
%** procedure 'TkReturnInt' in file "d:/cygwin/home/bruni/Projects/Mozart/Sources/share/lib/wp/Tk.oz", line 692, column 3, PC = 20928620
%** procedure 'ExecTk' in file "d:/cygwin/home/bruni/Projects/Mozart/mozart-stdlib/wp/qtk/QTkDevel.oz", line 528, column 3, PC = 20806000
%** procedure 'ForAllIndT' in file "/home/kost/compile/build-1.3.0/updates/mozart/share/lib/base/Record.oz", line 220, column 3, PC = 12076436
%** procedure 'QTkText,set' in file "d:/cygwin/home/bruni/Projects/Mozart/mozart-stdlib/wp/qtk/QTkText.oz", line 175, column 6, PC = 19895384
%** procedure 'QTkAction,execute' in file "d:/cygwin/home/bruni/Projects/Mozart/mozart-stdlib/wp/qtk/QTkDevel.oz", line 1290, column 6, PC = 20858188
%** procedure 'QTkButton,Execute/fast' in file "d:/cygwin/home/bruni/Projects/Mozart/mozart-stdlib/wp/qtk/QTkButton.oz", line 133, column 6, PC = 20916268
%** procedure 'Listen' in file "d:/cygwin/home/bruni/Projects/Mozart/mozart-stdlib/wp/qtk/QTk.oz", line 223, column 8, PC = 19803188
%**--------------------------------------------------------------
This is interesting because these addresses on d: drive do not exist!
 
The program code is
 
declare
[QTk]={Module.link["x-oz://system/wp/QTk.ozf"]}
FastPascal AddLists ZeroEnd ZeroFront PascalIO
 
proc {PascalIO}
   local
      HI HO N Window
      Desc=td(title:"Pascal's Triangle"
        lr(label(text:"Row Number:"
        glue:nw)
       entry(handle:HI)
       button(text:"Get"
       action:proc {$}
          N={FastPascal {String.toInt {HI get($)}}} in
          {Show N}   % Shows correctly at least up to row 11
          {HO set(N)}
       end))
    lr(label(text:"Contents of Row:")
       text(handle:HO
     height:5
     glue:we)))
   in
      Window={QTk.build Desc}
      {Window show}
   end
end
 
fun {FastPascal N}
   if N==1 then [1]
   else L in
      L={FastPascal N-1}
      {AddLists {ZeroEnd L} {ZeroFront L}}
   end
end
 
fun {AddLists L1 L2}
   case L1 of H1|T1 then
      case L2 of H2|T2 then
  H1+H2|{AddLists T1 T2}
      end
   else
      nil
   end
end
 
fun {ZeroEnd L}
   case L of H|T then
      H|{ZeroEnd T}
   else
      [0]
   end
end
 
fun {ZeroFront L}
   0|L
end
 
{PascalIO}
 
Alan
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to