Compare commits

...

3 Commits

13 changed files with 73 additions and 73 deletions

View File

@ -30,7 +30,7 @@ install:
before_script:
script:
- raco pkg install --deps search-auto --link afl
- raco test -x -p afl
- raco pkg install --deps search-auto --link afdl
- raco test -x -p afdl
after_script:

View File

@ -1,12 +1,12 @@
afl [![Build Status](https://travis-ci.org/AlexKnauth/afl.png?branch=master)](https://travis-ci.org/AlexKnauth/afl)
afdl [![Build Status](https://travis-ci.org/AlexKnauth/afdl.png?branch=master)](https://travis-ci.org/AlexKnauth/afdl)
===
a lang-extension for adding rackjure-like [anonymous function literals](http://www.greghendershott.com/rackjure/index.html#%28part._func-lit%29) to a language, based on at-exp and rackjure
documentation: http://pkg-build.racket-lang.org/doc/afl/index.html
documentation: http://pkg-build.racket-lang.org/doc/afdl/index.html
Example:
```racket
#lang afl racket/base
#lang afdl racket/base
(map (+ % 1) '(1 2 3)) ;=> '(2 3 4)
```

View File

@ -4,52 +4,52 @@
scribble-code-examples
(for-label (except-in racket/base
read read-syntax)
(except-in afl/reader
(except-in afdl/reader
read read-syntax)))
@title{afl}
@title{afdl}
@;; example: @afl-code{(map #λ(+ % 1) '(1 2 3))}
@(define-syntax-rule @afl-code[stuff ...]
@code[#:lang "afl racket" stuff ...])
@;; example: @afdl-code{(map #λ(+ % 1) '(1 2 3))}
@(define-syntax-rule @afdl-code[stuff ...]
@code[#:lang "afdl racket" stuff ...])
source code: @url["https://github.com/AlexKnauth/afl"]
source code: @url["https://github.com/AlexKnauth/afdl"]
@section{#lang afl}
@section{#lang afdl}
@defmodulelang[afl]{
The @racketmodname[afl] language is a lang-extension like @racketmodname[at-exp]
@defmodulelang[afdl]{
The @racketmodname[afdl] language is a lang-extension like @racketmodname[at-exp]
that adds @racketmodname[rackjure]-like anonymous function literals to a language.
@margin-note{see @secref["func-lit" #:doc '(lib "rackjure/rackjure.scrbl")]}
For example, @racket[@#,hash-lang[] @#,racketmodname[afl] @#,racketmodname[racket/base]]
For example, @racket[@#,hash-lang[] @#,racketmodname[afdl] @#,racketmodname[racket/base]]
adds anonymous function literals to @racketmodname[racket/base], so that
@codeblock{
#lang afl racket/base}
@code-examples[#:lang "afl racket/base" #:context #'here]|{
#lang afdl racket/base}
@code-examples[#:lang "afdl racket/base" #:context #'here]|{
(map #λ(+ % 1) '(1 2 3))
(map #λ(+ % %2) '(1 2 3) '(1 2 3))
}|
For the @racketmodname[afl] language to work properly for a module, the module
For the @racketmodname[afdl] language to work properly for a module, the module
has to depend on @racketmodname[racket/base] in some way, although that does not
mean it has to explicitly require it or that the language it uses has to provide
anything from it. It does mean that for instance
@racket[@#,hash-lang[] @#,racketmodname[afl] @#,racketmodname[racket/kernel]]
@racket[@#,hash-lang[] @#,racketmodname[afdl] @#,racketmodname[racket/kernel]]
won't work properly.
}
@section{afl/reader}
@section{afdl/reader}
@defmodule[afl/reader]
@defmodule[afdl/reader]
@deftogether[(@defproc[(afl-read [in input-port? (current-input-port)]
@deftogether[(@defproc[(afdl-read [in input-port? (current-input-port)]
[#:arg-str arg-str string? (current-arg-string)]) any]{}
@defproc[(afl-read-syntax [source-name any/c (object-name in)]
@defproc[(afdl-read-syntax [source-name any/c (object-name in)]
[in input-port? (current-input-port)]
[#:arg-str arg-str string? (current-arg-string)])
(or/c syntax? eof-object?)]{})]{
These procedures implement the @racketmodname[afl] reader. They do so by
These procedures implement the @racketmodname[afdl] reader. They do so by
constructing a readtable based on the current one, and using that
for reading.
@ -57,31 +57,31 @@ The @racket[arg-str] argument lets you specify something else to use as a placeh
@racket[%].
@examples[
(require afl/reader)
(afl-read (open-input-string "#λ(+ % %2)"))
(afl-read (open-input-string "#λ(+ _ _2)") #:arg-str "_")
(require afdl/reader)
(afdl-read (open-input-string "#λ(+ % %2)"))
(afdl-read (open-input-string "#λ(+ _ _2)") #:arg-str "_")
]
@racketmodname[afl/reader] also exports these functions under the names @racket[read] and
@racketmodname[afdl/reader] also exports these functions under the names @racket[read] and
@racket[read-syntax].
}
@defproc[(make-afl-readtable [orig-readtable readtable? (current-readtable)]
@defproc[(make-afdl-readtable [orig-readtable readtable? (current-readtable)]
[#:outer-scope outer-scope (-> syntax? syntax?)]
[#:arg-str arg-str string? (current-arg-string)]) readtable?]{
makes an @racketmodname[afl] readtable based on @racket[orig-readtable].
makes an @racketmodname[afdl] readtable based on @racket[orig-readtable].
The @racket[outer-scope] argument should be a function that introduce scopes to preserve hygiene,
normally produced by @racket[make-syntax-introducer] and similar functions. For versions of racket
that support it, these should generally be specified as use-site scopes.
The @racket[arg-str] argument lets you specify something else to use as a placeholder instead of
@racket[%], just like for @racket[afl-read].
@racket[%], just like for @racket[afdl-read].
}
@defproc[(use-afl-readtable [orig-readtable readtable? (current-readtable)]
@defproc[(use-afdl-readtable [orig-readtable readtable? (current-readtable)]
[#:arg-str arg-str string? (current-arg-string)]) void?]{
passes arguments to @racket[make-afl-readtable] and sets the @racket[current-readtable] parameter to
passes arguments to @racket[make-afdl-readtable] and sets the @racket[current-readtable] parameter to
the resulting readtable.
It also enables line counting for the @racket[current-input-port] via @racket[port-count-lines!].
@ -90,15 +90,15 @@ This is mostly useful for the REPL.
@verbatim{
Examples:
> @afl-code{(require afl/reader)}
> @afl-code{(use-afl-readtable)}
> @afl-code{(map #λ(+ % %2) '(1 2 3) '(1 2 3))}
> @afdl-code{(require afdl/reader)}
> @afdl-code{(use-afdl-readtable)}
> @afdl-code{(map #λ(+ % %2) '(1 2 3) '(1 2 3))}
@racketresult['(2 4 6)]
> @afl-code{(use-afl-readtable #:arg-str "_")}
> @afl-code{(map #λ(+ _ _2) '(1 2 3) '(1 2 3))}
> @afdl-code{(use-afdl-readtable #:arg-str "_")}
> @afdl-code{(map #λ(+ _ _2) '(1 2 3) '(1 2 3))}
@racketresult['(2 4 6)]
}}
@defparam[current-arg-string arg-str string?]{
a parameter that controls default values of the @racket[arg-str] arguments to @racket[afl-read] etc.
a parameter that controls default values of the @racket[arg-str] arguments to @racket[afdl-read] etc.
}

3
afdl/info.rkt Normal file
View File

@ -0,0 +1,3 @@
#lang info
(define scribblings '(["docs/afdl.scrbl" ()]))

View File

@ -13,7 +13,7 @@
(lambda (key default)
(case key
[(configure-runtime)
(define config-vec '#[afl/lang/runtime-config configure #f])
(define config-vec '#[afdl/lang/runtime-config configure #f])
(define other-config (other-get-info key default))
(cond [(list? other-config) (cons config-vec other-config)]
[else (list config-vec)])]

View File

@ -1,10 +1,10 @@
#lang lang-extension
#:lang-extension afl make-afl-lang-reader
#:lang-reader afl-lang
#:lang-extension afdl make-afdl-lang-reader
#:lang-reader afdl-lang
(require lang-reader/lang-reader
(only-in "../reader.rkt" wrap-reader))
(define (make-afl-lang-reader lang-reader)
(define (make-afdl-lang-reader lang-reader)
(define/lang-reader [-read -read-syntax -get-info] lang-reader)
(make-lang-reader
(wrap-reader -read)
@ -12,7 +12,7 @@
(lambda args
(define stx (apply read-syntax args))
(define old-prop (syntax-property stx 'module-language))
(define new-prop `#(afl/lang/language-info get-language-info ,old-prop))
(define new-prop `#(afdl/lang/language-info get-language-info ,old-prop))
(syntax-property stx 'module-language new-prop)))
-get-info))

View File

@ -0,0 +1,9 @@
#lang racket/base
(provide configure)
(require (only-in afdl/reader use-afdl-readtable))
(define (configure data)
(use-afdl-readtable))

View File

@ -1,14 +1,14 @@
#lang racket/base
(provide make-afl-readtable
afl-read
afl-read-syntax
(provide make-afdl-readtable
afdl-read
afdl-read-syntax
wrap-reader
use-afl-readtable
use-afdl-readtable
current-arg-string
(rename-out
[afl-read read]
[afl-read-syntax read-syntax])
[afdl-read read]
[afdl-read-syntax read-syntax])
)
(require racket/match
@ -45,19 +45,19 @@
(module+ test
(require rackunit))
(define (afl-read [in (current-input-port)] #:arg-str [arg-str (current-arg-string)])
(define (afdl-read [in (current-input-port)] #:arg-str [arg-str (current-arg-string)])
(parameterize ([current-arg-string arg-str])
((wrap-reader read) in)))
(define (afl-read-syntax [src (object-name (current-input-port))] [in (current-input-port)]
(define (afdl-read-syntax [src (object-name (current-input-port))] [in (current-input-port)]
#:arg-str [arg-str (current-arg-string)])
(parameterize ([current-arg-string arg-str])
((wrap-reader read-syntax) src in)))
(define (wrap-reader p)
(extend-reader p make-afl-readtable))
(extend-reader p make-afdl-readtable))
(define (make-afl-readtable [orig-rt (current-readtable)]
(define (make-afdl-readtable [orig-rt (current-readtable)]
#:outer-scope outer-scope
#:arg-str [arg-str (current-arg-string)])
(define reader-proc (make-reader-proc orig-rt outer-scope #:arg-str arg-str))
@ -67,19 +67,19 @@
[rt (make-readtable rt #\l 'dispatch-macro reader-proc)])
rt))
(define (use-afl-readtable [orig-rt (current-readtable)] #:arg-str [arg-str (current-arg-string)])
(define (use-afdl-readtable [orig-rt (current-readtable)] #:arg-str [arg-str (current-arg-string)])
(port-count-lines! (current-input-port))
(current-readtable (make-afl-readtable orig-rt #:outer-scope identity #:arg-str arg-str)))
(current-readtable (make-afdl-readtable orig-rt #:outer-scope identity #:arg-str arg-str)))
(define current-arg-string (make-parameter "%"))
(module+ test
(check-equal? (afl-read (open-input-string "#λ(+ % %2)"))
(check-equal? (afdl-read (open-input-string "#λ(+ % %2)"))
'(lambda (%1 %2)
(define-syntax % (make-rename-transformer #'%1))
(+ % %2)))
(check-equal? (afl-read (open-input-string "#λ(+ _ _2)") #:arg-str "_")
(check-equal? (afdl-read (open-input-string "#λ(+ _ _2)") #:arg-str "_")
'(lambda (_1 _2)
(define-syntax _ (make-rename-transformer #'_1))
(+ _ _2)))

View File

@ -1,4 +1,4 @@
#lang afl at-exp racket/base
#lang afdl at-exp racket/base
(require rackunit)
(check-equal? (map #λ(+ % 1) '(1 2 3))
'(2 3 4))

View File

@ -1,4 +1,4 @@
#lang afl racket/base
#lang afdl racket/base
(module+ test
(require rackunit)
(check-equal? (map (+ % 1) '(1 2 3))

View File

@ -1,4 +1,4 @@
#lang afl scribble/base
#lang afdl scribble/base
@(require rackunit)
@(check-equal? @#λ@title{@%}{This is a Title}
@title{This is a Title})

View File

@ -1,3 +0,0 @@
#lang info
(define scribblings '(["docs/afl.scrbl" ()]))

View File

@ -1,9 +0,0 @@
#lang racket/base
(provide configure)
(require (only-in afl/reader use-afl-readtable))
(define (configure data)
(use-afl-readtable))