[racket] Question about syntax splicing and formatting of the resulting code body

From: Grant Rettke (grettke at acm.org)
Date: Wed Jan 9 08:36:00 EST 2013

Hi,

I have the goal of inserting some Jess (http://herzberg.ca.sandia.gov/)
code inside of a Scribble interaction environment (eventually I will have a
language to evaluate this but I'm not there yet). Here is the relevant part
of the code I have to do that:

#lang racket

(define (my-read-syntax src in)
  (define path-ls (get-path in))
  (define path (list->string path-ls))
  (define fis (open-input-file #:mode 'text path))
  (define datums (let loop ()
                   (let* ((datum (read fis)))
                     (cond ((eof-object? datum) empty)
                           (else (cons datum (loop)))))))
  (close-input-port fis)
  (datum->syntax #f datums))

This does load the file and insert it into Scribble eg:

(interaction
    #:eval
    my-evaluator
    ((watch all)
     (reset)
     (defrule do-anything "A rule for anything." ?ne <- (anything) =>
(printout t "Someone did something.") (retract ?ne))
     (assert (anything))
     (run)))))

There are two things I'm still not doing correctly though:

#1. I've collected the contents of that file into a list of datums that
looks like this in DrRacket's console:

'((watch all)
  (reset)
  (defrule
   do-anything
   "A rule for anything."
   ?ne
   <-
   (anything)
   =>
   (printout t "Someone did something.")
   (retract ?ne))
  (assert (anything))
  (run))

I don't want those inserted as a list though, I only want the contents
inserted. Up above I see why it is happening, but I am not successfully
splicing it in my attempts. What is the right way?

#2. The code body is formatted at least in the output in DrRacket. When it
is inserted into the Scribble environment, though, it loses some of it's
formatting namely the defrule and right arrow appear in the same line. That
said, when Scribble renders it, all of the code is rendered on the same
line like this:

> ((watchall)(reset)(defruledo-anything"A rule for anything."?ne<-(anything)
=>(printoutt"Someone did something.")(retract?ne))(assert(anything))(run))

=>: arrow not allowed as an expression

How may I read in that file and then generated a syntax object that retains
the indentation and new lines?

#3. Am I generally going about this in an OK manner? My next part of the
plan to make a simple language whose only purpose in life is to evaluate
Jess code and print out the results; I want to be able to use Scribble for
any other Lispy language out there at least the interaction environment.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130109/9fe8d846/attachment.html>

Posted on the users mailing list.