postfix-dot-notation
1 #lang postfix-dot-notation
2 postfix-dot-notation for require
#%top
6.12

postfix-dot-notation

source code: https://github.com/AlexKnauth/postfix-dot-notation

1 #lang postfix-dot-notation

A lang-extension like at-exp that adds postfix-dot-notation to a language at the reader level.

Code like a.b is read as (b a), a.b.c is read as (c (b a)), and so on.

If you want to use an identifier that is supposed to have a dot in it, there are two cases where dot notation is disabled:
  • When an identifier is wrapped in ||, it is treated just like a normal identifier wrapped in ||. This means you can still use identifiers like |~.a| from racket/format or |pi.t| from racket/extflonum.

  • When an identifier begins with a ., it is treated as a normal Identifier. This means that identifiers like ... and .... work as normal.

#lang postfix-dot-notation racket
(define x "hello-world")
x.string->symbol ; 'hello-world
(struct foo (a b c))
(define y (foo 1 2 3))
y.foo-a ; 1
y.foo-b.number->string ; "2"
(parameterize ([error-print-width 10]) ; "(I am a..."
  (|~.a| '(I am a long list that spans more than (error-print-width))))
(match '(1 2 3) ; '(2 3)
  [(list 1 rst ...) rst])

2 postfix-dot-notation for require

This works through #%top, not at the reader level, so it only works when there is an undefined identifier with a dot in it.

Examples:
> (require postfix-dot-notation racket/local)
> (let  ([x "hello-world"])
    x.string->symbol)

'hello-world

> (local [(struct foo (a b c))
          (define x (foo 1 2 3))]
    (values x.foo-a
            x.foo-b.number->string))

1

"2"

syntax

(#%top . id)

The form that converts undefined identifiers that have dots in them, such as a.b to (b a), if b is defined and a is either defined or another identifier with a dot that can be converted like this.