From e338dd467219128d6edcd70c79a9168b0867d24c Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sun, 23 Feb 2003 05:08:15 +0000 Subject: [PATCH] Finished up the section on flow control and outlined the section on functions. Added example script output to figures. --- doc/gib/GIB.lyx | 335 ++++++++++++++++++++++++++++++++++++++++++- doc/gib/break.gib | 8 ++ doc/gib/continue.gib | 6 + doc/gib/examples.sh | 10 ++ doc/gib/for.gib | 3 + 5 files changed, 357 insertions(+), 5 deletions(-) create mode 100644 doc/gib/break.gib create mode 100644 doc/gib/continue.gib create mode 100755 doc/gib/examples.sh create mode 100644 doc/gib/for.gib diff --git a/doc/gib/GIB.lyx b/doc/gib/GIB.lyx index 8cd4f2d4c..067baf0bc 100644 --- a/doc/gib/GIB.lyx +++ b/doc/gib/GIB.lyx @@ -1389,7 +1389,15 @@ ifnot is as follows: \layout LyX-Code -if condition block1 [else block2] + +\family sans +if +\family default + condition block1 [ +\family sans +else +\family default + block2] \layout Standard Explanations of what each part means follow: @@ -1476,7 +1484,7 @@ if \begin_inset Float figure wide false -collapsed true +collapsed false \layout LyX-Code \line_top \line_bottom @@ -1487,6 +1495,20 @@ preview false \end_inset +\layout Standard + + +\series bold +Output: +\layout LyX-Code + + +\begin_inset Include \verbatiminput{if-simple.gib.out} +preview false + +\end_inset + + \layout Caption Simple @@ -1525,7 +1547,7 @@ else \begin_inset Float figure wide false -collapsed true +collapsed false \layout LyX-Code \line_top \line_bottom @@ -1536,6 +1558,20 @@ preview false \end_inset +\layout Standard + + +\series bold +Output: +\layout LyX-Code + + +\begin_inset Include \verbatiminput{if-else.gib.out} +preview false + +\end_inset + + \layout Caption @@ -1590,6 +1626,20 @@ preview false \end_inset +\layout Standard + + +\series bold +Output: +\layout LyX-Code + + +\begin_inset Include \verbatiminput{if-chain.gib.out} +preview false + +\end_inset + + \layout Caption Chained @@ -1650,7 +1700,11 @@ true. The formal syntax is: \layout LyX-Code -while condition block + +\family sans +while +\family default + condition block \layout Description condition is the same as @@ -1710,7 +1764,7 @@ while \begin_inset Float figure wide false -collapsed false +collapsed true \layout LyX-Code \line_top \line_bottom @@ -1750,4 +1804,275 @@ while \end_inset +\layout Subsubsection + + +\family typewriter +for +\layout Standard + +The for loop executes a program block once for every argument in a list. + Each execution, a variable will be set to the value of the current argument. + Syntax: +\layout LyX-Code + + +\family sans +for +\family default + variable +\family sans +in +\family default + list block +\layout Description + +variable is the variable that will be set to the value of the current argument + each time the program block is executed. +\layout Description + +in is a simple placeholder between +\family typewriter +variable +\family default + and +\family typewriter +list +\family default +. + It emphasizes the fact that +\emph on +for +\emph default + each argument +\emph on +in +\emph default + the list, the program block will be executed. +\layout Description + +list can be any number of arguments, including expansions. +\layout Description + +block must be the last argument to +\family typewriter +for +\family default +, and it must be a program block. +\layout Standard + +Figure +\begin_inset LatexCommand \vref{cap:for} + +\end_inset + + shows an example +\family typewriter +for +\family default + loop and its output. +\layout Standard + + +\begin_inset Float figure +wide false +collapsed false + +\layout LyX-Code +\line_top \line_bottom + +\begin_inset Include \verbatiminput{for.gib} +preview false + +\end_inset + + +\layout Standard + + +\series bold +Output: +\layout LyX-Code + + +\begin_inset Include \verbatiminput{for.gib.out} +preview false + +\end_inset + + +\layout Caption + +Example +\family typewriter +for +\family default + loop +\begin_inset LatexCommand \label{cap:for} + +\end_inset + + +\end_inset + + +\layout Subsubsection + +Additional Loop Functions: +\family typewriter +break +\family default + and +\family typewriter +continue +\layout Standard + +Two functions are available to control the behavior of loops during execution + of their program blocks: +\layout Description + +break immediately ends the program block and leaves the loop. +\layout Description + +continue returns to the top of the loop. + This means that +\family typewriter +while +\family default + loops check their condition argument again and +\family typewriter +for +\family default + loops move to the next argument in the list. +\layout Standard + +Figure +\begin_inset LatexCommand \vref{cap:break} + +\end_inset + + shows an example use of +\family typewriter +break +\family default + and its output, while Figure +\begin_inset LatexCommand \vref{cap:continue} + +\end_inset + + shows an example use of +\family typewriter +continue +\family default +. +\layout Standard + + +\begin_inset Float figure +wide false +collapsed false + +\layout LyX-Code +\line_top \line_bottom + +\begin_inset Include \verbatiminput{break.gib} +preview false + +\end_inset + + +\layout Standard + + +\series bold +Output: +\layout LyX-Code + + +\begin_inset Include \verbatiminput{break.gib.out} +preview false + +\end_inset + + +\layout Caption + +Example use of +\family typewriter +break +\begin_inset LatexCommand \label{cap:break} + +\end_inset + + +\end_inset + + +\layout Standard + + +\begin_inset Float figure +wide false +collapsed false + +\layout LyX-Code +\line_top \line_bottom + +\begin_inset Include \verbatiminput{continue.gib} +preview false + +\end_inset + + +\layout Standard + + +\series bold +Output: +\layout LyX-Code + + +\begin_inset Include \verbatiminput{continue.gib.out} +preview false + +\end_inset + + +\layout Caption + +Example use of +\family typewriter +continue +\begin_inset LatexCommand \label{cap:continue} + +\end_inset + + +\end_inset + + +\layout Section +\pagebreak_top +Functions +\layout Subsection + +Types and Concepts +\layout Subsection + +Defining Functions +\layout Subsection + +Accessing Arguments +\layout Subsection + +Return Values +\layout Subsubsection + +Returning Values from Functions +\layout Subsubsection + +Embedding Return Values +\layout Subsubsection + +Expanding Return Values \the_end diff --git a/doc/gib/break.gib b/doc/gib/break.gib new file mode 100644 index 000000000..38b4852ff --- /dev/null +++ b/doc/gib/break.gib @@ -0,0 +1,8 @@ +num = 4 +while $num { + echo Number: $num + if ($num == 2) { + break + } + num = ($num - 1) +} \ No newline at end of file diff --git a/doc/gib/continue.gib b/doc/gib/continue.gib new file mode 100644 index 000000000..5082f5b7d --- /dev/null +++ b/doc/gib/continue.gib @@ -0,0 +1,6 @@ +for num in 1 2 3 4 { + if ($num == 3) { + continue + } + echo Number: $num +} \ No newline at end of file diff --git a/doc/gib/examples.sh b/doc/gib/examples.sh new file mode 100755 index 000000000..eaaddd70f --- /dev/null +++ b/doc/gib/examples.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# +# This script is in the public f'ing domain. +# You can burn it to a CD and use it as a +# frisbee for all I care. + +for example in *.gib; do \ + carne "$example" >"${example}.out"; \ +done + diff --git a/doc/gib/for.gib b/doc/gib/for.gib new file mode 100644 index 000000000..d1bdbc584 --- /dev/null +++ b/doc/gib/for.gib @@ -0,0 +1,3 @@ +for num in 1 2 3 4 { + echo Number: $num +} \ No newline at end of file