Literate Programming in Scheme

The release notes here for PLT Scheme 4.1.5 mention support for literate programming. Not being familiar with the term; I read more about it on Wikipedia here.
I have wanted in-code documentation generation tools to serve this purpose; but I have never succeeded with them. It had always felt like I was battling the intent of the tool. Even Eiffel’s notion of different views on code-as-documentation never quite fit for me. This approach is fascinating; it allows for you to tell a story about the code as you write the code. Having posted to the PLT list asking about it here; two folks replied with details on this style and Scheme.
PLT Scheme recently added literate programming support; documented here. One example of its application is in Chat Noir here; and the source code for it may be viewed here (Thanks Robby).
A tool for literate programming in Scheme called is schemeweb located here (Thanks Phil).

The contentment of content

A few weeks on a PBS television show hosted by Alan Alda the scientists being interviewed were talking about the “Contentment of Content”. They said the the research shows that most humans learn the bulk of their knowledge (in particular their approach for all sorts of problem solving) younger in life and never learn any new approaches later on because it would just show them how much they don’t know. In other words; it would require the act of learning and that takes work. They go on to explain that in fact, this approach not only happens at the macro level in life but also in the macro level for particular areas of expertise. For sake of discussion, I would focus on programming.
The idea is that once you learn how; you are very, very unlikely to learn “new ways of doing it”, and why would you? It makes you feel bad since it makes you look like you don’t know what you are doing. It is also very, very unpopular to admit that you don’t know everything (I wonder if it has always been this way?). This is unfortunate because most of us really never learned how to program well and in fact seems to be the complete antithesis of the behavior and approaches that are likely to have made you successful as a programmer in the first place.

R6RS records and exports

In this post I asked:

Records conveniently generate a constructure and getters and setters for you.

Is there a way to conveniently export all these generated functions?

I am thinking of generating a helper function so I can copy and paste the exports; this is not ideal of course.

Aziz posted the following solution which works fine on PLT with Andrerui’s fix. I added code to make it in a standard library location:

redefine-record.sls


#!r6rs

;;;; Via comp.lang.scheme "R6RS records and exports"
;;;; By Aziz

;;; redefine-record.sls

(library
 (redefine-record redefine-record)
 (export redefine-record-type)
 (import (rnrs))

 (define-syntax redefine-record-type
   (syntax-rules ()
     [(_ record-name)
      (begin
        (define-syntax m
          (lambda (x)
            (define (fmt s1 stx . s*)
              (datum->syntax stx
                             (string->symbol
                              (apply string-append
                                     s1
                                     (symbol->string (syntax->datum stx))
                                     s*))))
            (define (enumerate i j)
              (if (= i j) '() (cons i (enumerate (+ i 1) j))))
            (syntax-case x ()
              [(_ ctxt)
               (let* ([rtd (record-type-descriptor
                            record-name)]
                      [f* (record-type-field-names rtd)]
                      [rcd (record-constructor-descriptor
                            record-name)])
                 (with-syntax ([make-T (fmt "make-" #'ctxt)]
                               [T? (fmt "" #'ctxt "?")]
                               [(n* (... ...))
                                (enumerate 0 (vector-length f*))]
                               [#(T-ref* (... ...))
                                (vector-map
                                 (lambda (x)
                                   (fmt "" #'ctxt "-" (symbol->string
                                                       x)))
                                 f*)])
                   #'(begin
                       (define make-T
                         (record-constructor
                          (record-constructor-descriptor
                           record-name)))
                       (define T?
                         (record-predicate
                          (record-type-descriptor
                           record-name)))
                       (define T-ref*
                         (record-accessor
                          (record-type-descriptor record-name)
                          n*))
                       (... ...))))])))
        (m record-name))])))


t1.sls


#!r6rs

;;;; Via comp.lang.scheme "R6RS records and exports"
;;;; By Aziz

;;; t1.sls

(library
 (redefine-record t1)
 (export M)
 (import (rnrs))

 (define-record-type M
   (fields x y z)))


t2.ss


#!r6rs

;;;; Via comp.lang.scheme "R6RS records and exports"
;;;; By Aziz and Andreuri

;;; t2.ss

(import (rnrs) (for (redefine-record t1) expand run) (redefine-record redefine-record))

(redefine-record-type M)

(define x (make-M 12 13 14))
(display (list x (M? x) (M-x x)))
(newline)

Run this to see it work:


plt-r6rs t2.sls
=> {#(struct:M 12 13 14) #t 12}

win-control

OLE, Internet Explorer and raw windows automation library for Gambit-C on Windows platforms

Inspired by Watir on Ruby, this library brings the same capabilities and more to the high-performing Gambit Scheme implementation. Now you can write automated test scripts or automate Windows application tasks in beautiful Scheme code and compile it all into a standalone exe file.

(via comp.lang.scheme)