[racket] phases

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jan 29 13:25:15 EST 2013

At Tue, 29 Jan 2013 19:18:13 +0100, Pierpaolo Bernardi wrote:
> what's the incantation needed to make the following work:

The right-hand side of `define-runtime-path' is evaluated at both
phases 0 and 1, so you need `sofa-version' and `arch' at both phase
levels.

Here's one way to do that:

----------------------------------------

#lang racket

(provide sofa-version)

(require ffi/unsafe)
(require ffi/unsafe/define)
(require racket/runtime-path)

(module sofa-params racket/base
  (provide sofa-version arch)
  (define sofa-version "20120301_a")
  (define arch
    (if (fixnum? #e10e15) 'x64 'x86)))

(require 'sofa-params
         (for-syntax 'sofa-params))

;; Access a file "data.txt" at run-time that is originally
;; located in the same directory as the module source file:
(define-runtime-path sofa.dll
  (format "sofa-~a-~a.dll" sofa-version arch))

(define-ffi-definer define-sofa (ffi-lib sofa.dll))


Posted on the users mailing list.