diff --git a/racket/remixd.rkt b/racket/remixd.rkt new file mode 100644 index 0000000..5f039fb --- /dev/null +++ b/racket/remixd.rkt @@ -0,0 +1,33 @@ +#lang racket/base +;; Move this into remix/stx0 + +(require (for-syntax racket/base + remix/stx/raw0)) + +(begin-for-syntax + (define (do-lang caller-id module-stx stx) + (syntax-case stx () + [(_ module-name s ...) + (identifier? #'module-name) + (let () + (define ip + (syntax-strings->input-port + (syntax-source stx) + (syntax->list #'(s ...)))) + (define mb + (parameterize ([read-accept-reader #t] + [read-accept-lang #t]) + (read-syntax #'module-name ip))) + (syntax-case mb () + [(_ _ module-lang body) + (quasisyntax/loc stx + (#,module-stx module-name module-lang body))] + [_ + (raise-syntax-error caller-id "Body did not read as module" stx mb)]))]))) + +(define-syntax (lang stx) + (do-lang 'lang #'module stx)) +(define-syntax (lang* stx) + (do-lang 'lang* #'module* stx)) + +(provide lang lang*) diff --git a/tests/racket/remixd.rkt b/tests/racket/remixd.rkt new file mode 100644 index 0000000..6ad14a1 --- /dev/null +++ b/tests/racket/remixd.rkt @@ -0,0 +1,77 @@ +#lang at-exp racket/base + +;; Some remix macros just work: +(require remix/datalog0) + +(define graph (make-theory)) +@datalog[graph]{ + edge(a, b). edge(b, c). edge(c, d). edge(d, a). + path(X, Y) :- edge(X, Y). + path(X, Y) :- edge(X, Z), path(Z, Y). + path(X, Y)? +} + +;; But others from remix/stx are specially exposed +(require racket/remixd) + +@lang[typed]{ +#lang typed/racket + +(: f (Float -> Float)) +(define (f x) + (+ x 5.0)) + +(f 8.0) + +(provide f) +} + +(module+ test + (require (submod ".." typed) + unstable/error) + (f 0.0) + (with-handlers ([exn:fail? + (λ (x) + (parameterize ([current-error-port (current-output-port)]) + (error-display x)))]) + (f 5))) + +(define (g x) + (+ x 6.0)) +(provide g) + +@lang*[main]{ +#lang typed/racket +(require/typed (submod "..") + [g (Float -> Float)]) + +(g 1.0) +} + +;; This works with different readers too, not just s-exprs + +@lang[db]{ +#lang datalog + +edge(a, b). edge(b, c). edge(c, d). edge(d, a). +path(X, Y) :- edge(X, Y). +path(X, Y) :- edge(X, Z), path(Z, Y). +path(X, Y)? +} + +(module+ test + (require (submod ".." db))) + +;; But if the reader itself uses @, then you need to quote it + +@lang[document]|{ +#lang scribble/manual + +@title{How to use Racket} + +It's pretty awesome +}| + +(module+ test + (require (prefix-in doc: (submod ".." document))) + doc:doc)