equals 23  
      1 pl/ 22
equals 'hello'  
      ('h' ap//// 'e') ap/ ('l' ap/ 'lo')
equals 'hello'  
      'he' ap/ 'l' ap// 'lo'
equals 25  
      3 ti/ 3 pl// 4 ti/ 4

equals 142  
      m= Dict new. m at/ 10 put/ 100. m at/ 10 pl// 42
equals 142  
      m= Dict new. m at// 4 pl/ 6 put// 10 ti/ 10. m at/ 10 pl// 42

equals 'ok'    
      3 lt/ 5   y//[ 'ok' ] n// [ 'oops' ]
equals 'oops'    
      8 lt/ 0 y//[ 'ok' ] n// [ 'oops' ]
equals 'ok'    
      2 lt/ 3   y//[ 'ok' ]
equals nil    
      8 lt/ 0    y//[ 'ok' ]
equals nil    
      -8 lt/ 0    n//[ 'ok' ]

equals 1
	'Vec' eq/ Vec name

equals VEC{ 4. 7. 9. }
    VEC{ 2 ti/ 2. 7. 3 ti/ 3. }

equals 'Vec'
	() cls name
equals 0
	() len
equals 'Vec'
	(8,) cls name
equals 1
	(8,) len
equals 25
	x, y = Vec{3. 4}. x ti/ x pl// y ti/ y.
equals 26
	x, y = 3, 4. x ti/ x pl// y ti/ y -- pl/ 1.

meth Vec eq/
  a cls name equals/ 'Vec'
    n// ['Vec.eq/ expected Vec argument, but got' err/ Vec{a. a cls. a cls name. a cls name equals/ 'Vec'} ]
    y// [
      self len eq/ a len
        n// ['Vec.eq/ got different length Vecs' err/ VEC{self. a}]
        y// [
          z= Vec new.
          self len do/ [ /i
	    z append/// self at/ i eq// a at/ i.
          ] .
          z
        ]
      ].

equals Vec{1. 1. 0.}
  Vec{'foo'. 100. 'z'} eq/ Vec{'foo'. 100. 'zoo'}

meth Vec collect/
    "Goldberg & Robson, 1989. p215"
    z= self cls new .
    self do/ [ /x .
      z ap/ ( a run/ x ) ] .
    z

equals VEC{ 100. 400. 900. }
  VEC{ 10. 20. 30. } collect/ [/x . x ti/ x]

meth Vec select/
    "Goldberg & Robson, 1989. p216"
    z= self cls new .
    self do/ [ /x .
      ( a run/ x ) y/ [
        z ap/ x ] ] .
    z

equals VEC{ 10. 20. }
  VEC{ 10. 20. 30. } select/ [/x . x lt/ 25]

meth Blk join/
  sb= Buf new.
  front= 1.
  self vec do/ [ /x .
    front y/ [front= 0]
          n/ [ sb ap/ a].
    sb ap/ x ].
  sb str.
meth Blk join
  self join/ ' '
meth Blk jam
  self join/ ''

meth Vec join/
  sb= Buf new.
  front= 1.
  self do/ [ /x .
    front y/ [front= 0]
          n/ [ sb ap/ a].
    sb ap/ x str ].
  sb str.
meth Vec join
  self join/ ' '
meth Vec jam
  self join/ ''

equals Vec{33. 44}
  33, 44
equals Vec{33. 44. 55}
  33, 44, 50 pl/ 4 -- pl/ 1

equals 'once upon a time'
  ['once'. 'upon'. 'a'. 'time']join/' '
  

class App Usr
class Home App

meth HomeCls footerButtons
  Vec{
      '|link|/|[RESET]|'.
      '|link|/Browse|[Browse]|'.
      '|link|/FormDoit|[Doit]|'.
      '|link|/DrawLine|[DrawLine]|'.
      '|link|/DrawStar|[DrawStar]|'.
  }

meth Home handle/query/
  "Default class for handling '/'."

  Dict new  at/ 'type' put/ 'list'
          -- at/ 'title' put/ a
          -- at/ 'value' put/ [
          [ '|link|/Browse|browse|' . 'Browse Classes.' ] vec .

          [ '|link|/FormDoit|doit|' . 'Evaluate code' ] vec .

        ] vec
        .


class Browse App
meth Browse handle/query/
  ww= a split/ '.' .  "It's a regexp."
  wl= ww len .
  clss= Cls all .

  "Start the list V with an UP link."
  v= [ '|link|/Home|[Home]|', 'Go Home.' ] vec .

  ( wl eq/ 1 ) y/ [
    "gk are Good Keys, those that are classes."
    gk= clss dir select/ [ /i .
        AND{ clss at/ i -- cls name ends/ 'Cls' .
             OR{ clss at/ i -- name ends/ 'Cls' -- not .
                 clss at/ i -- cls name eq/ 'ClsCls' . } } ] .


    gk do/ [ /k .
        kc= clss at/ k .
        kn= kc name .
        v ap/ ( Jam{'|link|/Browse.' . kn . '|' . kn . '|'}, kc meths join/ ' ' ) .
        ] .



    z= Dict new  at/ 'type' put/ 'list'
          -- at/ 'title' put/ 'Browsing All Classes'
          -- at/ 'extra' put/ ( clss )
          -- at/ 'extraKeys' put/ ( clss dir )
          -- at/ 'extraCollect' put/ ( clss dir collect/ [ /i . ( clss at/ i ) cls cls name ] )
          -- at/ 'extraSelect' put/ gk
          -- at/ 'value' put/ v
        .

  ] .
  
  ( wl eq/ 2 ) y/ [
    cn= ww at/ 1 .  "class name"
    co= clss at/ cn toLower .   "class object"

    d= co cls methDefs .
    d dir do/ [ /x . "For each class method"
      v ap/ ( Jam{ '|link|/EditMethod.' . cn . 'Cls.' . x . '|class ' . x. '|' }, d at/ x -- str ) .
    ] .

    d= co methDefs .
    d dir do/ [ /x . "For each instance method"
      v ap/ ( Jam{ '|link|/EditMethod.' . cn . '.' . x . '|' . x. '|' }, d at/ x -- str ) .
    ] .

    z= Dict new  at/ 'type' put/ 'list'
          -- at/ 'title' put/ ( 'Browsing Class' ap/ cn )
          -- at/ 'value' put/ v
        .

  ] .
  z .


class EditMethod App
meth EditMethod handle/query/
  ww= a split/ '.' .
  wl= ww len .
  clss= Cls all .

  ( wl ne/ 3 ) y/ [ Zork foo ] .

  cn= ww at/ 1 .  "class name"
  mn= ww at/ 2 .  "method name"

  co= clss at/ cn toLower .   "class object"
  mo= co methDefs at/ mn .  "method object"

  z= Dict new  at/ 'type' p/ 'edit'
          -- at/ 'title' p/ ( 'Editing Class' ap/ cn -- ap/ ' Method ' -- ap/ mn )
          -- at/ 'value' p/ ( mo str )
          -- at/ 'action' p/ ( '/SubmitMethod' )
          -- at/ 'field1' p/ 'ClassName'
          -- at/ 'value1' p/ cn
          -- at/ 'field2' p/ 'MethodName'
          -- at/ 'value2' p/ mn
        .
  z .


class SubmitMethod App
meth SubmitMethod handle/query/
  clss= Cls all .

  cname= b at/ 'ClassName' .
  mname= b at/ 'MethodName' .

  co= clss at/ cname tolower .

  z= co definemethod/ mname abbrev/ '' doc/ '' code/ ( b at/ 'text' ) .

  DICT[
  	'type' . 'list' .
	'title' . Join{ 'Submitted Class'. cname . ' Method '. mname }.
	'value' . Vec{ Vec{ '|link|/Home|Home|' } }.
	'URL' . a .
	'QUERY' . b .
	'Z' . z .
  ] .


class FormDoit App
meth FormDoit handle/query/
  DICT[ 'type' . 'edit' .
       'title' . 'Doit Form' .
       'value' . '' .
       'action' . '/SubmitDoit' .
  ] .


class SubmitDoit App
meth SubmitDoit handle/query/
  z= Tmp new eval/ ( b at/ 'text' ) .
  DICT[ 'type' . 'text' .
       'title' . [ 'doit/' . ( b at/ 'text' ) str ] join/ ' ' .
       'value' . z str .
  ] .


class DrawLine App
meth DrawLine handle/query/
  DICT{ 'type'. 'draw'.
	'title'. 'Drawing a line'.
	'value'. Vec{
           Vec{ 'line'. 10. 400. 50. 300. 2 }.
	}.
	'width'. 300.
	'height'. 500.
  }


class DrawStar App
meth DrawStar handle/query/
  i = 0.
  j = 0.

  v= Vec new.
  Vec{ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. } do/ [ /i
    Vec{ 0.0. 0.1. 0.2. 0.3. 0.4. 0.5. 0.6. 0.7. 0.8. 0.9 } do/ [ /j
      x= i pl/ j --sin ti/ 290 --pl/ 300.
      y= i pl/ j --cos ti/ 290 --pl/ 300.
      v ap/ Vec{ 'line'. 300. 300. x. y. }.
    ]
  ].

  DICT{ 'type'. 'draw'.
	'title'. 'Drawing a line'.
	'value'. v.
	'width'. 600.
	'height'. 600.
  }

