INTERCAL on Interstates Examples

Hello, world!

Simply specify a template name inside rabbit-ears as an argument to READ OUT.

NOTE At the start of the program, handle the default route.

DO COME FROM (16000)
PLEASE READ OUT #0 WITH TEMPLATE "hello.html"
GIVE UP

Routing and templating

INTERCAL on Interstates can take advantage of a unique and powerful feature of the INTERCAL language – COME FROM. Just define all possible places a route can be accessed from and it can't be accessed from any others. You can only COME FROM WITH ROUTE from a line which READS OUT WITH TEMPLATE. (Experienced INTERCAL programmers may consider it a kind of computed COME FROM). Static link checking and URL security all in one simple instruction!

The current route parameters live in ;4400. The set of parameters to the template is stored in ;49221. You will note that we have added an extra clause (WITH ROUTE) to the COME FROM statement to restrict the types of routes available. The ASCII strings inside rabbit-ears are merely syntactic sugar; ick will translate them into an appropriate onespot array.

        NOTE At the start of the program, handle the default route.
        DO (15) NEXT
            
(2)     DO COME FROM (16) WITH ROUTE "/blog/post/:id"

        PLEASE DO ,1 <- ;4400 SUB #1
        PLEASE NOTE ,1 now contains the first argument passed 
        NOTE to the route.

        NOTE This is where you could load up some data based upon ,1.
        NOTE For the purposes of this example, assume we loaded 
        NOTE our data into ,4, ,5, and ,6.
        DO STASH ;49221 SUB #1 <- ,4
        DO STASH ;49221 SUB #2 <- ,5
        DO STASH ;49221 SUB #3 <- ,6

        NOTE Render the template. 
        NOTE Pass #3 because there are three arguments.
        PLEASE READ OUT #3 WITH TEMPLATE "blog_post.html"
        PLEASE GIVE UP

        NOTE This is the default page of the website.
(15)    DO COME FROM (16000) WITH ROUTE "/home"
        NOTE Render the template. Pass #0 if no parameters are required.
(16)    READ OUT #0 WITH TEMPLATE "home.html"
        PLEASE GIVE UP

Inside templates, put INTERCAL expressions inside double grumpies ({{}}). ;49221 has already been extracted for you starting at ,144 and counting downwards.

<!-- blog_post.html -->
<h1>{{,144}}</h1> <!-- Title -->
<h3>Posted {{,143}}</h3> <!-- Date -->
<p>{{,142}}</p> <!-- Blog post text -->

Database access

INTERCAL's SELECT and MINGLE operators have been extended to set-based operations. Interstates' ActiveCassette library (an implementation of the ActiveRecord pattern) then translates them to SQL.

NOTE Retrieves row 1 from table 0 into ;1, then extracts 
NOTE column 3, then renders a template using it.
DO COME FROM (16000)

NOTE Use sparks to create an order of operations.
PLEASE DO STASH ;49221 SUB #1 <- 'FROM DATABASE #0~#1' SUB #3
DO READ OUT #1 WITH TEMPLATE "db_sample.html"
PLEASE GIVE UP

Let's bring it together with the above routing example. Here, we use MINGLE to select multiple columns.

PLEASE NOTE Retrieves the specified blog post from the database,
PLEASE NOTE then renders a template using it.

DO COME FROM (16000) WITH ROUTE "/blog/post/:id"
DO STASH ,3 <- ;4400 SUB #1

NOTE Use multiple MINGLE to specify multiple columns.
NOTE Multiple columns in a FROM DATABASE clause will 
NOTE automatically fill an array.
PLEASE NOTE Specify the HAVING clause to constrain
NOTE results, in this case column #0 must equal ,3
DO STASH ;49221 <- 'FROM DATABASE #1~#3$#4$#5' HAVING #0 ,3
READ OUT #3 WITH TEMPLATE "blog_post.html"
PLEASE GIVE UP