SRFI-105 "Curly Infix" for Racket
1 Pragmas
1.1 Strict mode:   using the reader as the original SRFI 105
1.2 Type annotation:   ANNOTATION-ON and ANNOTATION-OFF
1.3 Quoted lists:   CARE-OF-QUOTES-ON and CARE-OF-QUOTES-OFF
2 Converting a Scheme+   file into a Scheme file
9.3

SRFI-105 "Curly Infix" for Racket🔗ℹ

Scheme Request For Implementations 105

Install as a package.

Use:

#lang reader SRFI-105

or:

 #reader SRFI-105 package: SRFI-105-for-Racket
This reader package provides the SRFI-105 Curly Infix reader/parser.

Designed to be used with Scheme+:

This package provides the Scheme+ language definitions.

1 Pragmas🔗ℹ

A pragma is a bare symbol written in the source code: it is recognized by the reader while it reads the file, not by the Racket compiler, and it does not remain in the code.

Pragmas

  

Effect

  

At the beginning of each file

  

Region

BEGIN-STRICT-SRFI-105-REGION
END-STRICT-SRFI-105-REGION

  

the curly brackets follow SRFI 105
(see Strict mode: using the reader as the original SRFI 105) or the rules of Scheme+

  

rules of Scheme+

  

from the pragma to the other one
or to the end of the file

ANNOTATION-ON
ANNOTATION-OFF

  

type annotation and inference pass of Scheme+
on or off

  

off

  

the elements that follow the pragma in the same list
and all that is nested in them

CARE-OF-QUOTES-ON
CARE-OF-QUOTES-OFF

  

the quoted lists are data,
or infix expressions (symbolic computation)

  

on (data)

  

as ANNOTATION-ON

A pragma is written alone, or alone in curly brackets ({BEGIN-STRICT-SRFI-105-REGION}). It can be written inside a list (the body of the module form, of a procedure, ...) or at the top level of the file, before the module form, where it acts on the whole module. A pragma acts only on the file where it is written, not on the modules this file requires: each file starts in the state of the table.

1.1 Strict mode: using the reader as the original SRFI 105🔗ℹ

Between BEGIN-STRICT-SRFI-105-REGION and END-STRICT-SRFI-105-REGION the reader follows SRFI 105, as the original reader: {a} is a, {a b} is (a b), {a op b op c} with a single operator is (op a b c) (also with if), the () are not infix, and the other expressions are ($nfx$ …). As in SRFI 105, the neoteric expressions f(x), f{x} and x[i] are recognized only inside curly brackets, in both modes: outside, f(x) is read as the two data f and (x).

The main differences with the rules of Scheme+:

Expression

  

Scheme+

  

Strict mode

{a + b * c}

  

(+ a (* b c))

  

($nfx$ a + b * c)

'{a + b * c}

  

'(+ a (* b c))

  

'($nfx$ a + b * c)

{n !}

  

(! n)

  

(n !)

{a if b}

  

(if b a)

  

(if a b)

{f x}

  

decided at run time

  

(f x)

{a + b + c} , {- x} , {x}

  

(+ a b c) , (- x) , x

  

the same

Racket defines neither $nfx$ (used for the expressions that are not simple infix) nor $bracket-apply$ (used for x[i]): SRFI 105 leaves them to the programmer. Define them yourself, or take them from Scheme+, where $nfx$ evaluates the expression with the precedence of the operators. A whole file in strict mode, as with the original reader:

#lang reader SRFI-105
BEGIN-STRICT-SRFI-105-REGION
(module m racket
  (require (only-in Scheme+ $nfx$ $bracket-apply$))
  (define (f x) {x * 2})
  (define v #(10 20 30))
  (display (list {2 + 3 * 4} {f(5) + v[1] * 2} '{a + b * c}))
  (newline))

displays (14 50 ($nfx$ a + b * c)).

At the REPL, type the pragma alone (or alone in curly brackets): the mode changes for the rest of the session.

1.2 Type annotation: ANNOTATION-ON and ANNOTATION-OFF🔗ℹ

The pragmas ANNOTATION-ON and ANNOTATION-OFF turn on or off, by region, the type annotation and inference pass of Scheme+ (see the section Type annotation and inference of the Scheme+ documentation): a pragma acts on the elements that follow it in the same list and on all that is nested in them, until the other pragma or the end of the list. The pass is off at the beginning of each file: a pragma acts only on the file where it is written, not on the modules this file requires. It can be written inside the module form or at the top level of the file (before the module form, it acts on the whole module).

At the REPL, type the pragma alone: it turns the annotation on or off for the rest of the session, the expressions typed between ANNOTATION-ON and ANNOTATION-OFF are a region. The REPL starts in the state left by the file it was started from (REPL-Scheme-PLUS.rkt of Scheme+ has ANNOTATION-ON), and ANNOTATION-ON also works in a REPL started without a file: it then creates the tables of the annotation, the tables of a file already read are kept.

1.3 Quoted lists: CARE-OF-QUOTES-ON and CARE-OF-QUOTES-OFF🔗ℹ

The pragmas CARE-OF-QUOTES-ON and CARE-OF-QUOTES-OFF act by region too, on the quoted lists (see the section Pragmas of the Scheme+ documentation): with CARE-OF-QUOTES-ON, the state at the beginning of each file, a quoted list is data and a quoted {} is converted at its top level only; CARE-OF-QUOTES-OFF opens a region for the symbolic computation, where the quoted and quasiquoted lists are infix expressions at all levels ('(x + y * z) is '(+ x (* y z))).

2 Converting a Scheme+ file into a Scheme file🔗ℹ

The command line tool src/curly-infix2prefix4racket.rkt of this package converts a Scheme+ file into the Racket code that the reader gives to the compiler, for example to debug it with the Racket tools (error line numbers, macro stepper, ...):

racket curly-infix2prefix4racket.rkt [--verbose] file+.rkt > file.rkt

The converted code is written on the standard output. When the Scheme+ file has the pragma ANNOTATION-ON, it is the annotated code, the same as the code compiled by the reader; it never contains the type forms nor the pragmas. With the option –verbose, the banner and the state of the type annotation are displayed on the error output. The Makefile of the Scheme+ examples uses this tool to generate the files of the parsed_files_directory directory.

Documentation of the original SRFI 105