THE META-HTML LANGUAGE REFERENCE MANUAL

Packages [TOC] Arithmetic Operators

Section Intro: Flow Control

Flow Control

Synopsis:

    Meta-HTML contains commands for controlling which of a set of statements will be executed, and for repetitive execution of a set of statements.

    Such commands constitute what is called flow control, since they tell the Meta-HTML interpreter where or what the next statement to interpret resides.

    All of the flow control operators in Meta-HTML take a test and some additional statements; the closest thing to a goto statement in Meta-HTML is the redirect command.

Commands:

Variables:

<breakSimple

    Unconditionally and immediately stop the execution of the nearest surrounding while or foreach.

    Example usage:

    <while true>
      ;;; Check to see if the user has changed the file.
      <if <file-newer? <get-var foo.c> <get-var foo.o>>
        <break>>
    <p>
      ;;; Not changed yet, so do some more in the background.
      <process-chunk <get-var chunk-num>>
      <increment chunk-num>
    </while>

<concat &rest args>Simple

    Concatenate all of the arguments given, creating a single token with no intervening whitespace. This is quite useful for those situations where intervening whitespace would look bad in the output, but the input source would be unreadable without any.

    For example:

    <concat <textarea name=label rows=10 cols=40>
            <get-var-once label>
            </textarea>>

<group &rest args>Simple

    Combine all of the material passed into a single Meta-HTML statement. This is the primitive for grouping multiple statements where only a single statement is expected. Whitespace within the group is preserved, making this command useful for assigning to array variables.

    Some examples:

    <set-var array[] =
      <group this is element 0
             this is element 1
             this is element 2>>

    <if <eq this that>
        <group <h2> This is equal to That </h2>>
       <group <h2> This is NOT equal to That </h2>>>

    Although group is a primitive in Meta-HTML, it could have been defined as:

      <defsubst group &body body><get-var-once body></defsubst>

<if TEST &optional [THEN] [ELSE]Simple

    First TEST is evaluated. If the result does not contain only whitespace characters the THEN clause is evaluated, otherwise, the ELSE clause is evaluated. Although Meta-HTML has the relational operator or, you can efficiently test for the presence of any of a group of variables with code similar to the following:

    <if <get-var foo bar>
       "Either FOO or BAR is present"
      "Neither FOO nor BAR is present">

<ifeq THIS THAT &optional [THEN] [ELSE] &key [CASELESS=TRUE]Simple

    The THIS and THAT clauses are evaluated. If the results are text-wise identical, then the THEN clause is evaluated, otherwise, the ELSE clause is evaluated. If CASELESS=TRUE is given, the text-wise comparison of the values is done with no regard to upper and lower case distinctions.

<ifneq THIS THAT &optional [THEN] [ELSE] &key [CASELESS=TRUE]Simple

    The THIS and THAT clauses are evaluated. If the results are not text-wise identical, then the THEN clause is evaluated, otherwise, the ELSE clause is evaluated. If CASELESS=TRUE is given, the text-wise comparison of the values is done with no regard to upper and lower case distinctions.

<match-case &optional [NAME=REGEXP] [CONSEQUENT...] [DEFAULT] [DEFAULT-CONSEQUENT]Simple

    For each NAME=VALUE pair, the value of NAME is compared with the regular expression REGEXP. If the expression matches, then the corresponding CONSEQUENT code is performed, and its value is the return value of the <match-case> form.

    If none of the clauses match, and there is a default clause, then the DEFAULT-CONSEQUENT is evaluated, and its return value is the return value of the <match-case> form.

    match-case is especially useful as a `traffic switch' to select one of several actions based on a user button press.

<prog &rest args>Simple

<return &rest args>Simple

    Unconditionally and immediately stop the execution of the current function, macro, while or foreach statement, and return the evaluated ARGS.

    Example usage:

    <define-function countdown start stop>
      <if <eq start stop>
          <return BlastOff!>>
      <get-var start>, 
      <countdown <sub start 1> <get-var stop>>
    </define-function>
    <countdown 10 4>
    produces:
    10, 9, 8, 7, 6, 5, BlastOff!

<var-case &optional [NAME=VALUE] [CONSEQUENT...] [DEFAULT] [DEFAULT-CONSEQUENT]Simple

    For each NAME=VALUE pair, the value of NAME is string-wise compared with VALUE. If they are identical, then the corresponding CONSEQUENT code is performed, and its value is the return value of the <var-case> form.

    If none of the clauses match, and there is a default clause, then the DEFAULT-CONSEQUENT is evaluated, and its return value is the return value of the <var-case> form.

    var-case is especially useful as a `traffic switch' to select one of several actions based on a user button press.

    For example:

    <var-case
       action="Save Files"      <save-files <get-var posted::files[]>>
       action="Delete Files"    <delete-files <get-var posted::files[]>>
       action="Rename Files"    <redirect
                                     rename-files.mhtml?<cgi-encode files>>>

<when TEST
  body
</when>
Complex

    Evaluate TEST. If the result is a non-empty string, then execute the BODY statements. This is a cleaner way to handle optional multiple statement execution rather than dealing with quoting everything inside of an if form.

<while TEST
  body
</while>
Complex

    TEST is evaluated. If the result is a non-empty string, then the BODY statements are evaluated, and the process is repeated.

<with &optional [VAR=VAL...]
  body
</with>
Complex

    Execute BODY in an environment where VAR has the value VAL. Execution takes place in the current package. After execution, the value of VAR is restored to the value that it had before encountering the with macro.

    <set-var x=hello>
    <with x=1 z=<get-var foo>> <get-var x> </with>
    <get-var x>
    produces:
    1 
    hello

Edit Section
Function Index
Variable Index


The META-HTML Reference Manual V2.0 Copyright © 1995, 1998, Brian J. Fox
Found a bug? Send mail to bug-manual@metahtml.org