Re: TIB: Back to TI-BASICs


[Prev][Next][Index][Thread]

Re: TIB: Back to TI-BASICs




Jody wrote:
[...]

> Yuck! How can you read those "programmer friendly" displays. Take, for
> instance, put the extra space in between certain things. That drives
> me bonkers!


An extra return here and there? :-)

It only makes the text easier to read.
Just remember, only do it when you "change the subject" as in
literature.

> Whenever I look through the code, I keep thinking that I
> forgot something.

What do you mean?
By sorting the code into chunks you only have to make sure that one
chunk works and is correctly finished (with endwhile's and such), then
you can move on to the next.

> I also have trouble looking at indentations as
> helpful.

Look again :-)

> As far as I'm concerned they make things more confusing. This
> is probably just because calculators are the only things I've
> programmed and my brain is trained into looking at the next line right
> under the last.

Hmmm...

For i,1,|#lines|,1
Look at line i
if line=empty
 skip
(blah blah blah)
endfor

...it's that easy. :-)

Try having a look at these two programs (I recommend a fast
scroll-through :-)

unindented:
-----------
Proc Show[H, TotalH: History,B: Buttons,D: Document](b: URL,w,h,s: Int)
(+
Type anch = Prod(depth:Int,f:URL)
Var ankh:anch
Var d: Display'Data
Var pressed:Text
Var help:URL
Var i:Int
Var prompt:Prompt'Data
Proc Interpret[H, TotalH: History,B: Buttons,d:
Display'Data,ankh:anch](b: URL,body: HTML0)
(+
Var i,j,x0,y0,x1,y1: Int
i:=0
do i < |body| ->
if is(body.(i),word) ->
Display'Word[d](body.(i).word)
if (ankh.depth > 0) and (Display'Visible[d]) ->
Display'Position[d,x1,y1]
printlength[j](body.(i).word++" ")
x0:=x1-j
y0,y1:=y1,y1+14
Display'NewButton[d,B](x0,y0,x1,y1,ankh.f)
fi
& is(body.(i),anchor) ->
ankh.depth:=ankh.depth+1
Display'AnchorMode[d]
j:=0
do j<F'Len[TotalH] ->
if b++body.(i).anchor.f=F'Sel[TotalH](j) ->
Display'SeenMode[d]
j:=F'Len[TotalH]
fi
j:=j+1
od 
ankh.f:=body.(i).anchor.f
Interpret[H,TotalH,B,d,ankh](b,body.(i).anchor.h)
ankh.depth:=ankh.depth-1
if ankh.depth=0 ->
Display'NormalMode[d]
& true ->
Display'AnchorMode[d]
fi
& is(body.(i),bold) ->
Display'BoldStyle[d]
Interpret[H,TotalH,B,d,ankh](b,body.(i).bold)
Display'PopStyle[d]
& is(body.(i),italics) ->
Display'ItalicStyle[d]
Interpret[H,TotalH,B,d,ankh](b,body.(i).italics)
Display'PopStyle[d]
& is(body.(i),h1) ->
Display'LargeSize[d]
Display'BoldStyle[d]
Interpret[H,TotalH,B,d,ankh](b,body.(i).h1)
Display'PopStyle[d]
Display'PopSize[d]
Display'Paragraph[d]
& is(body.(i),paragraph) ->
Display'Paragraph[d]
& is(body.(i),break) ->
Display'Break[d]
& is(body.(i),hrule) ->
Display'Rule[d]
& is(body.(i),image) ->
if RelativeUrl(body.(i).image) ->
FetchGif(b,body.(i).image)
& true ->
FetchGif("",body.(i).image)
fi
Display'Image[d]("/tmp/"++UserId()++".gif")
if ankh.depth > 0 ->
gifsize[x0,y0]("/tmp/"++UserId()++".gif")
Display'Position[d,x1,y1]
if (y0 < (y1-66)) and (Display'Visible[d]) ->
Display'NewButton[d,B](x1-x0,y1+14-y0,x1,y1+14,ankh.f)
fi
fi
& is(body.(i),ulist) ->
(+ Var j: Int
j:=0
Display'Paragraph[d]
Display'PushMargin[d]
do j < |body.(i).ulist| ->
Display'Break[d]
Display'Dot[d]
Interpret[H,TotalH,B,d,ankh](b,body.(i).ulist.(j))
j:=j+1
od
Display'PopMargin[d]
Display'Paragraph[d]
+)
fi
i:=i+1
od
+)
end Interpret
setcolor("white")
fill(0,0,w,h-70)
setcolor("black")
jumpto(w-30,6)
showgif("stop.gif")
Display'Init[d](h-90,66,w-20,18,20,s)
do true ->
Click'Init[B]
jumpto(10,10)
showgif("back.gif")
Display'NewButton[d,B](10,10,50,51,"back")
jumpto(60,10)
showgif("home.gif")
Display'NewButton[d,B](60,10,100,51,"home")
jumpto(110,10)
showgif("reload.gif")
Display'NewButton[d,B](110,10,150,51,"reload")
jumpto(160,10)
showgif("open.gif")
Display'NewButton[d,B](160,10,200,51,"open")
jumpto(210,10)
showgif("scroll.gif")
Display'NewButton[d,B](212,38,223,50,"up")
Display'NewButton[d,B](212,12,223,24,"down")
ankh:=Prod(0,"")
Interpret[H,TotalH,B,d,ankh](Url2Base(b),D.body)
setcolor("white")
fill(w-30,6,w-6,30)
setcolor("black")
pressed:=Click'Get[B]
if pressed="back" ->
if F'Len[H]>1 ->
F'Rpop[H]
help:=F'Rtop[H]
F'Rpop[H]
Open[H,TotalH]("",help,"home.html")
fi
& pressed="home" ->
Open[H,TotalH]("","home.html","home.html")
& pressed="reload" ->
Open[H, TotalH]("",F'Rtop[H],"home.html")
& pressed="open" ->
Prompt'Init[prompt]
Prompt'Title[prompt]("da pROmPt")
Prompt'Geometry[prompt](450,30,200,200)
Prompt'Item[prompt]("URL:","http://")
Prompt'Show[prompt]
b:=Prompt'Response[prompt]("URL:")
Open[H,TotalH]("",b,"home.html")
& pressed="up" ->
s:=s+1
if s=1 ->
s:=0
fi
& (pressed="down") ->
if Display'Visible[d] ->
s:=s+1
fi
s:=s-1
& true ->
Open[H,TotalH](Url2Base(F'Rtop[H]),pressed,"home.html")
fi
Show[H,TotalH,B,D](b,w,h,s)
od
+)
end Show

--------------------------------------------------------
--------------------------------------------------------

OK, take a look at:

Same procedure, indented:
-----------------------
   Proc Show[H, TotalH: History,B: Buttons,D: Document](b: URL,w,h,s:
Int)
     (+
	Type anch = Prod(depth:Int,f:URL)

	Var ankh:anch
	Var d: Display'Data
	Var pressed:Text
	Var help:URL
	Var i:Int
	Var prompt:Prompt'Data

        Proc Interpret[H, TotalH: History,B: Buttons,d:
Display'Data,ankh:anch](b: URL,body: HTML0)
	  (+
	     Var i,j,x0,y0,x1,y1: Int
	     
	     i:=0
	     
             do i < |body| ->
		if is(body.(i),word) ->
		   Display'Word[d](body.(i).word)
		   if (ankh.depth > 0) and (Display'Visible[d]) ->
		      Display'Position[d,x1,y1]
		      printlength[j](body.(i).word++" ")
		      x0:=x1-j
		      y0,y1:=y1,y1+14
		      Display'NewButton[d,B](x0,y0,x1,y1,ankh.f)
		   fi
		 & is(body.(i),anchor) ->
		   ankh.depth:=ankh.depth+1
		   Display'AnchorMode[d]
		   j:=0
		   do j<F'Len[TotalH] ->
		      if b++body.(i).anchor.f=F'Sel[TotalH](j) ->
			 Display'SeenMode[d]
			 j:=F'Len[TotalH]
		      fi
	              j:=j+1
	           od 
		   ankh.f:=body.(i).anchor.f
		   Interpret[H,TotalH,B,d,ankh](b,body.(i).anchor.h)
		   ankh.depth:=ankh.depth-1
		   if ankh.depth=0 ->
		      Display'NormalMode[d]
		    & true ->
		      Display'AnchorMode[d]
		   fi
		 & is(body.(i),bold) ->
		   Display'BoldStyle[d]
		   Interpret[H,TotalH,B,d,ankh](b,body.(i).bold)
		   Display'PopStyle[d]
		 & is(body.(i),italics) ->
		   Display'ItalicStyle[d]
		   Interpret[H,TotalH,B,d,ankh](b,body.(i).italics)
		   Display'PopStyle[d]
		 & is(body.(i),h1) ->
		   Display'LargeSize[d]
		   Display'BoldStyle[d]
		   Interpret[H,TotalH,B,d,ankh](b,body.(i).h1)
		   Display'PopStyle[d]
		   Display'PopSize[d]
		   Display'Paragraph[d]
		 & is(body.(i),paragraph) ->
		   Display'Paragraph[d]
		 & is(body.(i),break) ->
		   Display'Break[d]
		 & is(body.(i),hrule) ->
		   Display'Rule[d]
		 & is(body.(i),image) ->
		   if RelativeUrl(body.(i).image) ->
		      FetchGif(b,body.(i).image)
		    & true ->
		      FetchGif("",body.(i).image)
		   fi
		   Display'Image[d]("/tmp/"++UserId()++".gif")
		   if ankh.depth > 0 ->
		      gifsize[x0,y0]("/tmp/"++UserId()++".gif")
		      Display'Position[d,x1,y1]
		      if (y0 < (y1-66)) and (Display'Visible[d]) ->
			 Display'NewButton[d,B](x1-x0,y1+14-y0,x1,y1+14,ankh.f)
		      fi
		   fi
		 & is(body.(i),ulist) ->
		   (+ Var j: Int
		      j:=0
		      Display'Paragraph[d]
		      Display'PushMargin[d]
		      do j < |body.(i).ulist| ->
			 Display'Break[d]
			 Display'Dot[d]
			 Interpret[H,TotalH,B,d,ankh](b,body.(i).ulist.(j))
			 j:=j+1
		      od
		      Display'PopMargin[d]
		      Display'Paragraph[d]
		   +)
		fi
		i:=i+1
             od
          +)
        end Interpret

	setcolor("white")
	fill(0,0,w,h-70)
	setcolor("black")
	
	jumpto(w-30,6)
	showgif("stop.gif")
	
        Display'Init[d](h-90,66,w-20,18,20,s)
	
	do true ->
	   Click'Init[B]
	   jumpto(10,10)
	   showgif("back.gif")
	   Display'NewButton[d,B](10,10,50,51,"back")
	   jumpto(60,10)
	   showgif("home.gif")
	   Display'NewButton[d,B](60,10,100,51,"home")
	   jumpto(110,10)
	   showgif("reload.gif")
	   Display'NewButton[d,B](110,10,150,51,"reload")
	   jumpto(160,10)
	   showgif("open.gif")
	   Display'NewButton[d,B](160,10,200,51,"open")
	   jumpto(210,10)
	   showgif("scroll.gif")
	   Display'NewButton[d,B](212,38,223,50,"up")
	   Display'NewButton[d,B](212,12,223,24,"down")

	   ankh:=Prod(0,"")
	   Interpret[H,TotalH,B,d,ankh](Url2Base(b),D.body)
	
	   setcolor("white")
	   fill(w-30,6,w-6,30)
	   setcolor("black")

	   pressed:=Click'Get[B]

	   if pressed="back" ->
	      if F'Len[H]>1 ->
		 F'Rpop[H]
		 help:=F'Rtop[H]
		 F'Rpop[H]
		 Open[H,TotalH]("",help,"home.html")
	      fi
	    & pressed="home" ->
	      Open[H,TotalH]("","home.html","home.html")
	    & pressed="reload" ->
	      Open[H, TotalH]("",F'Rtop[H],"home.html")
	    & pressed="open" ->
	      Prompt'Init[prompt]
	      Prompt'Title[prompt]("da pROmPt")
	      Prompt'Geometry[prompt](450,30,200,200)
	      Prompt'Item[prompt]("URL:","http://")
	      Prompt'Show[prompt]
	      b:=Prompt'Response[prompt]("URL:")
	      Open[H,TotalH]("",b,"home.html")
            & pressed="up" ->
              s:=s+1
	      if s=1 ->
		 s:=0
	      fi
            & (pressed="down") ->
	      if Display'Visible[d] ->
		 s:=s+1
	      fi
	      s:=s-1
	    & true ->
	      Open[H,TotalH](Url2Base(F'Rtop[H]),pressed,"home.html")
           fi
	   
	   Show[H,TotalH,B,D](b,w,h,s)
	od
     +)
   end Show

--------------------------------------------------------
--------------------------------------------------------

...Note how easy it was to find the beginnings and endings of each do,
if, and such, in the second program compared to the first.
Now do you see? :-)

The above to procedures are from the web-browser I programmed last
semester. A lot of places you see [Text]'[Text]. This is an indirection
to other procedures, or sub-programs (called 'boxes' in this language).
Without subprograms the browser would have been an impossible project,
especially due to a massive use of recursion.

-- 
          Rene Kragh Pedersen
------------------------------------------------------------------
man: Why did you get a divorce?
man:: Too many arguments.


Follow-Ups: References: