Commits

Brian Mearns  committed 8db99e6

More work on the tutorial: describing the processing routine, nested Lists, etc.

  • Participants
  • Parent commits 4ba68b5

Comments (0)

Files changed (1)

File templ/tutorial.templ

 
         }} % end section "Hello, ..."
 
+        {section "The temple Processing Routine" {'
+
+            {p
+<<<As mentioned, a template file consists of text and expressions. In general, {templ} expressions can be
+Lists or Strings, but at the top level, only Lists are treated as expressions, everything else is treated as text.>>>
+            }
+
+            {p
+<<<When a top level List element is encountered by the {templ} processor, the entire List is parsed and then {em evaluated}. 
+Generally, Lists in a template file represent an {em executable} to be invoked (like the {code echo} function
+we saw above). The first element of the List specifies the executable to invoke, and the remaining elements are the arguments
+to pass. Like a lot of other programming languages, the arguments are generally each evaluated one at a time before invoking
+the executable and passing in the values that result from the evaluation. {em Unlike} a lot of programming languages, the
+elements of the List are evaluated in order from {em left to right}.
+This is important because the first element of the List, the one that specifies the executable to invoke, must also be 
+evaluated, and then {em resolved}. We'll learn more about what this means and why it matters later, but for now, just keep
+in mind that arguments are evaluated left to right.>>>
+            }
+
+            {p
+<<<When evaluating the elements of the List, Strings are {em self-evaluating}, meaning that when they are evaluated, the
+resulting value is simply the String value itself. Nested Lists (elements of a List which are themselves Lists), are
+evaluated just like top level Lists are: as describing an executable to invoke and the arguments to pass to it.>>>
+            }
+
+            {EXAMPLE-TEMPLATE "text"
+
+                {implode
+<<<The following template uses a nested List, and introduces another built-in function, {code glue}, which simply
+joins multiple String values together in the order given.>>>
+                }
+
+                {implode
+<<<The result is (suprise, surprise) the same thing as before.>>>
+                }
+
+"{echo {glue \"hello, \" \"templ!\"}}"
+
+            }
+
+            {p
+<<<To evaluate the top level List, the {code echo} String element
+is evaluated first. Strings are self evaluating, so this just results in the String value {code "\"echo\""}, which resolves
+to the {code echo} function we've seen before (don't worry about resolution right now).>>>
+            }
+
+            {p
+<<<The second element of the top level List is a nested list, so it needs to be evaluated next. This evaluates by invoking
+the {code glue} function to glue together the two given Strings. This entire list (the nested one) therefore evaluates to
+the String object {code "\"hello, templ!\""}.>>>
+            }
+
+            {p
+<<<So after evaluating the elements of the top list, we end up with an expression that invokes the {code echo} function with
+the argument {code "\"hello, templ!\""}, just like we had before.>>>
+            }
+
+        }} % end section "...Processor"
+
     }} %end section "Introduction"
         
 }}{#