First draft
This commit is contained in:
parent
977756d25f
commit
96ef21b0cb
33
racket/remixd.rkt
Normal file
33
racket/remixd.rkt
Normal file
|
@ -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*)
|
77
tests/racket/remixd.rkt
Normal file
77
tests/racket/remixd.rkt
Normal file
|
@ -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)
|
Loading…
Reference in New Issue
Block a user