[racket] racket's template system: expand: unbound identifier

From: Daniel Bastos (dbastos at toledo.com)
Date: Thu Nov 24 17:06:00 EST 2011

Good evening, gentlemen.

I'm studying


to see how web development is done in Racket. Having written a first
hello world using templates, I'm wishing to use the @in[] call. So I

%cat templates1.rkt
#lang racket
(require web-server/servlet

(define (start req)
    (let ([friends
           (list (cons "John" "Smith")
                 (cons "Jack" "Smith")
                 (cons "Joseph" "Smith"))])
       (include-template "friends.html"))))

(define (response/doit text)
    #"Okey dokey"
    (list (string->bytes/utf-8 text))))

(serve/servlet start
  #:port 80
  #:servlet-path "/"
  #:command-line? #t)

I'm getting

%racket templates1.rkt
friends.html:4:18: expand: unbound identifier in module in: c

 === context ===

%cat friends.html

   @in[c friends] {
    <tr><td>@(car c), @(cdr c)</td></tr>

Could you point towards a direction where I can always take a further
step to dig in and find what's going wrong? (Although I'm so new at
the technology that I might be unable to follow instructions.)

Here's what I'm trying to do. I wrote templates2.rkt to test the
include-template function.

%cat templates2.rkt
#lang racket
(require web-server/servlet

(define (start req)
    (include-template "nothing.html")))

[... more code omitted ...]

%cat nothing.html

%rlwrap racket
Welcome to Racket v5.2.0.3.
> (load "templates2.rkt")
> (expand (include-template "nothing.html"))
reference to undefined identifier: include-template

I thought that by loading templates2.rkt, I could spare me from
requiring web-server/templates.

> (require web-server/templates)
> (include-template "nothing.html")

> (expand (include-template "nothing.html"))
#<syntax (quote "hi")>

> (syntax->datum (expand (include-template "nothing.html")))

> (syntax->datum (expand (include-template "friends.html")))
reference to undefined identifier: friends

 === context ===
/home/dbastos/plt/collects/racket/port.rkt:63:0: with-output-to-string

My plan was to see a little further what the code in friends.html is
doing, but then I need to bind friends to something before I try to.
But if I do that, the other c-unbound-identifier error will blow
anyway and I won't see the code. I wish I could see the code before
executing it. How do you guys do it?

Posted on the users mailing list.