afl
1 #lang afl
2 afl/  reader
afl-read
afl-read-syntax
make-afl-readtable
use-afl-readtable
current-arg-string
8.12

afl🔗ℹ

source code: https://github.com/AlexKnauth/afl

1 #lang afl🔗ℹ

 #lang afl package: afl

The afl language is a lang-extension like at-exp that adds rackjure-like anonymous function literals to a language.

For example, #lang afl racket/base adds anonymous function literals to racket/base, so that
#lang afl racket/base

>

 

(map (+ % 1) '(1 2 3))

'(2 3 4)

>

 

(map (+ % %2) '(1 2 3) '(1 2 3))

'(2 4 6)

For the afl language to work properly for a module, the module has to depend on 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 #lang afl racket/kernel won’t work properly.

2 afl/reader🔗ℹ

 (require afl/reader) package: afl

procedure

(afl-read [in #:arg-str arg-str])  any

  in : input-port? = (current-input-port)
  arg-str : string? = (current-arg-string)

procedure

(afl-read-syntax [source-name 
  in 
  #:arg-str arg-str]) 
  (or/c syntax? eof-object?)
  source-name : any/c = (object-name in)
  in : input-port? = (current-input-port)
  arg-str : string? = (current-arg-string)
These procedures implement the afl reader. They do so by constructing a readtable based on the current one, and using that for reading.

The arg-str argument lets you specify something else to use as a placeholder instead of %.

Examples:
> (require afl/reader)
> (afl-read (open-input-string "#λ(+ % %2)"))

'(lambda (%1 %2) (define-syntax % (make-rename-transformer #'%1)) (+ % %2))

> (afl-read (open-input-string "#λ(+ _ _2)") #:arg-str "_")

'(lambda (_1 _2) (define-syntax _ (make-rename-transformer #'_1)) (+ _ _2))

afl/reader also exports these functions under the names read and read-syntax.

procedure

(make-afl-readtable [orig-readtable]    
  #:outer-scope outer-scope    
  [#:arg-str arg-str])  readtable?
  orig-readtable : readtable? = (current-readtable)
  outer-scope : (-> syntax? syntax?)
  arg-str : string? = (current-arg-string)
makes an afl readtable based on orig-readtable.

The outer-scope argument should be a function that introduce scopes to preserve hygiene, normally produced by make-syntax-introducer and similar functions. For versions of racket that support it, these should generally be specified as use-site scopes.

The arg-str argument lets you specify something else to use as a placeholder instead of %, just like for afl-read.

procedure

(use-afl-readtable [orig-readtable    
  #:arg-str arg-str])  void?
  orig-readtable : readtable? = (current-readtable)
  arg-str : string? = (current-arg-string)
passes arguments to make-afl-readtable and sets the current-readtable parameter to the resulting readtable. It also enables line counting for the current-input-port via port-count-lines!.

This is mostly useful for the REPL.

Examples:

 

> (require afl/reader)

> (use-afl-readtable)

> (map (+ % %2) '(1 2 3) '(1 2 3))

'(2 4 6)

> (use-afl-readtable #:arg-str "_")

> (map (+ _ _2) '(1 2 3) '(1 2 3))

'(2 4 6)

parameter

(current-arg-string)  string?

(current-arg-string arg-str)  void?
  arg-str : string?
a parameter that controls default values of the arg-str arguments to afl-read etc.