[plt-scheme] question about syntax-unquoted procedure

From: Jos Koot (jos.koot at telefonica.net)
Date: Tue Apr 29 07:54:34 EDT 2008

Consider:

#lang scheme
(require (for-syntax some-library)) ; exports procedure F : string ... --> procedure

(define-syntax (do-at-compile-time-only stx)
 (syntax-case stx ( )
  ((_ name . list-of-strings)
   (let ((list-of-strings (syntax->datum (syntax list-of-strings))))
    (if (andmap string? list-of-strings)
     (quasiquote-syntax
      (define name
       (unquote-syntax
        (apply F list-of-strings))))
     (raise-syntax-error etc))))))

(provide do-at-compile-time-only)

Require the above module
(do-at-compile-time-only f "string" ...)
(f arg ...) 

I did some tests with this. It seems to work alright, but I cannot find it as a documented feature, which makes me suspicious. Can it be trusted? Of course syntax do-at-compile-time-only must be given string-constants. It does not accept exprs that evaluate to strings. For a simple procedure F, simply writing (define f (F "string" ...)) may be optimized such as to evaluate (F "string" ...) once only at compile time. I don't know whether or not the optimizer does do such things, but anyway I'm afraid my F is too complicated for the optimizer such as to detect that (F "string" ...) is in fact a constant across various run times and threads. The whole idea is to apply F once during compilation in order that there is no need to call F during every run time.

Kind regars, Jos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080429/56a9d7ac/attachment.html>

Posted on the users mailing list.