[racket] abstracting over codeblock

From: Shriram Krishnamurthi (sk at cs.brown.edu)
Date: Thu Sep 8 21:22:31 EDT 2011

Thanks: that makes sense.  But in that case, setting aside the
abstraction issue for a moment, could you explain why

@codeblock{
           (define (f x) (x "three"))
           }

works as expected -- it colors the sub-parts as the appropriate
syntactic categories, not all as string -- but

@codeblock[
           (define (f x) (x "three"))
           ]

does not:

  define: not allowed in an expression context in: (define (f x) (x
  "three"))

?  That doesn't quite match my understanding of "`codeblock' expects
code, and it's a macro that does the quoting itself".

I did see in the Scribble docs the difference between {} and [], but
now the interaction between macros (which work top-down) and
expressions (which work bottom-up) is not so clear to me.

Also, related to this and going back to the abstraction issue, when I
type the very thing you suggested:

 @(define-syntax-rule (mycode code ...) (codeblock code ...))

 @mycode[
   foo
   bar]

I get:

Welcome to DrRacket, version 5.1.3 [3m].
Language: scribble/manual; memory limit: 128 MB.
. expand: unbound identifier in module in: foo

pointing to the foo inside the [brackets], whereas

@mycode{
   foo
   (define (f x) (x "three" 1 #\c))
   bar}

is handled and colored correctly....

Thanks!

Shriram


Posted on the users mailing list.