Rivet examples

These are some examples, rather limited ones, of what can be done with Rivet.

\n" for {set j 1} {$j <= 8} {incr j} { set num [ expr {$i * $j * 4 - 1} ] puts [ format "\n" $num $num $num ] } incr i puts "\n" } puts "

Hello world

<?
cookie "foo" "bar" # we have to put this before any 'puts' statements

puts "Hello world"
?>

Produces:


Conditionals:

<? if { 1 } { ?>

<h2> True </h2>

<? }  ?>

Produces:

True


Loops:

<? 
set x 0 
while { $x < 5 } { 
 puts "\$x = $x<br>"
 incr x
?>

LOOP<br>

<? }  ?>

Produces:

" incr x ?> LOOP


Variables (environmental as well as those passed to the script)


<? 
 hgetvars
if { [ array exists VARS ] } {
    puts "< ul>"
    foreach { vr } [ array names VARS ]  {
        puts "<li>(VARS) $vr = $VARS($vr)"
    }
    puts "</ul>"
}

if { [ array exists ENVS ] } {
    
    puts "<ul>"
    foreach { vr } [ array names ENVS ]  {
        puts "<li>(ENVS) $vr = $ENVS($vr)"
    }
    puts "</ul>"
}

if { [ array exists COOKIES ] } {
    
    puts "<ul>"
    foreach { vr } [ array names COOKIES ]  {
        puts "<li>(COOKIES) $vr = $COOKIES($vr)"
    }
    puts "</ul>"
}

?>

Produces:

" foreach { vr } [ array names VARS ] { puts "

  • (VARS) $vr = $VARS($vr)" } puts "" } if { [ array exists ENVS ] } { puts "
      " foreach { vr } [ array names ENVS ] { puts "
    • (ENVS) $vr = $ENVS($vr)" } puts "
    " } if { [ array exists COOKIES ] } { puts "
      " foreach { vr } [ array names COOKIES ] { puts "
    • (COOKIES) $vr = $COOKIES($vr)" } puts "
    " } ?>

  • Create a table on the fly

    
    <?
    set i 1
    puts "<table>\n"
    
    while { $i <= 8 } {
        puts "<tr>\n"
        for {set j 1} {$j <= 8} {incr j} {
    	set num [ expr $i * $j * 4 - 1]
    	puts [ format "<td bgcolor=%2x%2x%2x > $num $num $num </td>\n" $num $num $num ]
        }
        incr i
        puts "</tr>\n"
    }
    
    puts "</table>\n"
    ?>
    
    Produces:

    \n" while { $i <= 8 } { puts "

    $num $num $num
    \n" ?>


    In addition
    There are many, many other things you can do with Rivet. You can, if everything is compiled right, load tcl modules, like libpgtcl.so (the Postgresql interface), so that you can interact with a database!

    Return to the Rivet homepage