giving up with being able to define resources in expression position, and going back to define-resource

This commit is contained in:
Danny Yoo 2011-08-12 14:57:53 -04:00
parent bc8369b25c
commit 3190ee2f60
3 changed files with 27 additions and 36 deletions

View File

@ -1,4 +1,10 @@
#lang planet dyoo/whalesong #lang planet dyoo/whalesong
(require (planet dyoo/whalesong/resource)) (require (planet dyoo/whalesong/resource))
(file-resource "images/humpback.jpg") (define-resource whale-resource "images/humpback.jpg")
#;(define whale-image
(image-url
(resource->url whale-resource)))
#;whale-image

View File

@ -61,7 +61,7 @@
e e
null null
#%plain-module-begin #%plain-module-begin
(rename-out [my-module-begin #%module-begin]) #%module-begin
#%datum #%datum
#%app #%app
#%top-interaction #%top-interaction
@ -98,6 +98,7 @@
unless unless
require require
for-syntax for-syntax
for-template
define-for-syntax define-for-syntax
begin-for-syntax begin-for-syntax
prefix-in prefix-in
@ -438,17 +439,4 @@ symbol->string
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-syntax (my-module-begin stx)
(syntax-case stx ()
[(_ body ...)
(with-syntax ([(expanded-body ...)
(local-expand #'(body ...)
'module-begin
#f)])
(syntax/loc stx
(#%module-begin expanded-body ...)))]))

View File

@ -1,29 +1,26 @@
#lang s-exp "../lang/kernel.rkt" #lang s-exp "../lang/kernel.rkt"
;; Macros for recording the definition of resources in a program.
(provide file-resource) (require (for-syntax racket/base
racket/path
syntax/parse))
(provide define-resource)
(require "structs.rkt") (require "structs.rkt")
;; Macros for recording the definition of resources in a program.
(require (for-syntax racket/base))
;; file-resource: ;; file-resource:
;; ;;
(define-syntax (file-resource stx) (define-syntax (define-resource stx)
(syntax-case stx () (syntax-parse stx
[(_ path) [(_ name:id path:str)
(let ([dontcare (with-syntax ([normal-path
(syntax-local-lift-expression #'(begin (normalize-path (build-path
(begin-for-syntax (or (current-load-relative-directory)
(printf "Compile time code executing")) (current-directory))
(void)))]) (syntax-e #'path)))])
(syntax/loc stx (syntax/loc stx
(let-syntax ([compile-time-code (begin (begin-for-syntax
(lambda (stx) (printf "compile time code executing; we need to save ~s\n"
(printf "compile time code executing\n") normal-path))
#'(void))]) (define name (resource path)))))]))
(begin
;;dontcare
(resource path)))))]))