aful
1 #lang aful
2 aful/  reader
aful-read
aful-read-syntax
make-aful-readtable
use-aful-readtable
current-arg-string
6.12

aful

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

1 #lang aful

 #lang aful package: aful

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

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

>

 

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

'(2 3 4)

>

 

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

'(2 4 6)

For the aful 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 aful racket/kernel won’t work properly.

2 aful/reader

 (require aful/reader) package: aful

procedure

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

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

procedure

(aful-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 aful 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 aful/reader)
> (aful-read (open-input-string "#λ(+ % %2)"))

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

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

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

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

procedure

(make-aful-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 aful 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 aful-read.

procedure

(use-aful-readtable [orig-readtable    
  #:arg-str arg-str])  void?
  orig-readtable : readtable? = (current-readtable)
  arg-str : string? = (current-arg-string)
passes arguments to make-aful-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 aful/reader)

> (use-aful-readtable)

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

'(2 4 6)

> (use-aful-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 aful-read etc.