# Melting prefix and infix expression with scheme+ for racket

**URL:** https://racket.discourse.group/t/melting-prefix-and-infix-expression-with-scheme-for-racket/3802
**Category:** Show & Tell
**Created:** [June 21, 2025, 8:59am UTC](https://racket.discourse.group/t/melting-prefix-and-infix-expression-with-scheme-for-racket/3802 "2025-06-21T08:59:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)
#### Post date: [June 21, 2025, 8:59am UTC](https://racket.discourse.group/t/melting-prefix-and-infix-expression-with-scheme-for-racket/3802/1 "2025-06-21T08:59:45Z")

</div>

Hi "[Racketeers](https://www.youtube.com/watch?v=MBB-hMt9240)" 🙂 ,

i present the lastest feature of scheme+ for racket that allow the melting in an expression of both infix and prefix sub-expressions.  
There is a disambiguating algorithm based on a finite state machine.  
Note that some expression would need to be detected not only at the syntax parsing but at the execution stage.(which is not yet implemented,will be in future version).

This feature allow to get rid of use of special { } curly brackets as it is now auto-detected by scheme syntax transformers, and so you just have to use normal ( ) parenthesis.  
But then you have to use a special definition procedure called `define+` but i have modified in scheme+ the classic `define` of scheme to integrate in it the `define+` special feature, still with 100% compatibility with scheme. So you rarely have to use `define+`.  
As there is no more needs to use { } you can get rid of the use of `#lang reader SRFI-105` if you just use the infix/prefix syntax, but if you want to use the indexing via [] yo still need the SRFI-105 parser.

Note that it could be strange to mix infix and prefix sub-expressions in an expression it is more logic to keep the same syntax in all the expression. It just could be possible because the algorithm is recursive and check the syntax for all the sub expressions, allowing the mix

Here is some concrete examples:

Note that i really prefer for infix definitions a syntax like `{x := infix_expressions ...}` instead of `(define x infix_expressions ...)`

```scheme
Welcome to DrRacket, version 8.17 [cs].
Language: racket, with debugging; memory limit: 14000 MB.
> (require Scheme+)

Scheme+ v10.0 by Damien Mattei

(define x 3 * 5 + 2)
x
17

(define t 3 * (+ 2 4) - 1)
t
17

(define z (3 + 1) * (2 * (+ 2 1) - (sin 0.3)) + ((* 2 5) - 5))
z
27.817919173354642

(define x 1 + 2 + 3)
x
6

(define k 10.0 - 3.0 - 4.0 + 1 - 5.0 * 2.0 **3.0 / 7.0** 3.0)
k
3.883381924198251

(define a 7)
(define b 3)
(define r a * - b)
r
-21

(define s 3 ² + 2 · 3 · 5 + 5 ²)
s
64

(define s 3 ² + 2 * 3 * 5 + 5 ²)
s
64

```

And here is a simple list of examples or piece of code tested or running REPL-SRFI-105-Racket.rkt :

```scheme
Welcome to DrRacket, version 8.14 [cs].
Language: reader SRFI-105, with debugging; memory limit: 8192 MB.
SRFI 105 Curly Infix for Scheme+ v9.8
SRFI-105 Curly Infix parser for Racket Scheme and R6RS by Damien MATTEI
(based on code from David A. Wheeler and Alan Manuel K. Gloria.)

Possibly skipping some header's lines containing space,tabs,new line,etc or comments.

SRFI-105.rkt : number of skipped lines (comments, spaces, directives,...) at header's beginning : 12

Parsed curly infix code result = 

(module repl racket (provide (all-defined-out)) (require Scheme+))

Scheme+ v10.0 by Damien Mattei

;; examples in REPL begins here:
{3 * (+ 2 4) - 1}
17

{(- 7 (3 * (+ 2 4) - 1))}
-10

{(3 + 1) * (2 * (+ 2 1) - sin(0.3)) + ((* 2 5) - 5)}
27.817919173354642
;; the above is in prefix : (+ (* (+ 3 1) (- (* 2 (+ 2 1)) (sin 0.3))) (- (* 2 5) 5))

(define n 7)
{2 * (- n 4)}
6

(define a 3)
(define b 5)
{n + (- b a)}
9

```

Here is a few more syntax available in this version of Scheme+ with SRFI-105 reader:

```scheme
#lang SRFI-105
(require Scheme+)

```

```scheme
(define (foo x y) {-4 · sin(x) + x · y ² - 5 · x / y})
(foo 1.23 3.4)
8.640021262861444

{2 ³}
8

{3 · (2 ³ - 1)}
21

{(2 ³) ⁴}
4096

(define+ (chaos p q d x0 y0)
  
  ;;(define a {2 * cos{2 * pi * p / q}}) ; or {2 * (cos {2 * pi * p / q})} or {2 * cos({2 * pi * p / q})}
  (define a 2 * (cos (2 * pi * p / q)))
  (define+ ksx (√ ((2 + a) / 2)) ) ;; (sqrt {(2 + a) / 2})) ; or sqrt{{2 + a} / 2}
  {ksy := (√ ((2 - a) / 2))} ; (sqrt {(2 - a) / 2})} ; or (define ksy (sqrt {{2 - a} / 2}))
  
  (stream-map (lambda (z)
                (match-let (((vector x y) z))
                  (vector ((ksx / (√ 2)) * (x + y))
			  {(ksy / (√ 2)) * ((- x) + y)})))
                  (stream-iterate (lambda (z)
                                    (match-let (((vector x y) z))
                                      (vector
                                       ;;((a * x) + y + (d * x) / (add1 (x ** 2))) ; infix left to right evaluation avoid extra parenthesis but is hard for humans
				       ((a * x) + y + (d * x) / (add1 (x ²)))
				       (- x))))
				  (vector x0 y0))))

(define+ (line-length x0 y0 x1 y1)
  (√ ((x1 - x0) ² + (y1 - y0) ²)))

```

Scheme+ and SRFI-105 reader are available on Github:

[SRFI-105 curly infix reader](https://github.com/damien-mattei/SRFI-105-for-Racket)

[Scheme+](https://github.com/damien-mattei/Scheme-PLUS-for-Racket)

---

<div class="post-metadata">

### Author: ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)
#### Post date: [June 27, 2025, 10:35am UTC](https://racket.discourse.group/t/melting-prefix-and-infix-expression-with-scheme-for-racket/3802/2 "2025-06-27T10:35:05Z")

</div>

I'm interesting in any feedback from the Github dowloaders/cloners as i can see. Feel free to contact me in any way to give your feedback , i would really know how it is used, any idea about features to code or even critics or lack of something or bugs if any, or something not clear in doc. I can be joined on Racket discourse or discord or by email in firstname dot lastname (the same as here) @univ-cotedazur.fr .

I now have released the code available on Racket package but here i can not see the downloads as in github :

> **[SRFI-105-for-Racket](https://pkgs.racket-lang.org/package/SRFI-105-for-Racket)**
>
> SRFI 105 implementation and more
> use with #lang SRFI-105

> **[Scheme-PLUS-for-Racket](https://pkgs.racket-lang.org/package/Scheme-PLUS-for-Racket)**
>
> Scheme+ for Racket
> use with SRFI 105:
> \#lang SRFI-105
> (require Scheme+)

"Take this opportunity to get it. Only a few copies left." 😂

---

<div class="post-metadata">

### Author: ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)
#### Post date: [July 21, 2025, 8:07pm UTC](https://racket.discourse.group/t/melting-prefix-and-infix-expression-with-scheme-for-racket/3802/3 "2025-07-21T20:07:52Z")

</div>

I released a new version of Scheme+

New feature of version 10.3:

Allow multiples In/equalities in expression, examples:

```scheme

(when {0 ≤ x0 ≤ xws and 0 ≤ x1 ≤ xws and
       0 ≤ y0 ≤ ywsp and 0 ≤ y1 ≤ ywsp}
     (send dc draw-line
		   x0 y0
		   x1 y1))

{#t and (#f or 1 < 2 <= 2)}
#t

{#t and (#f or 1 < 2 < 2)}
#f

```

works again with a FSM (Finite state Machine):

 ![in-equality](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/3/3cf84b15ac7169b3fbfa870227c0d38003649b63.jpeg)

For curiosity code is [here](https://github.com/damien-mattei/Scheme-PLUS-for-Racket/blob/main/in-equalities.rkt).

The full code of Scheme+ and the [reader SRFI-105](https://github.com/damien-mattei/SRFI-105-for-Racket) that parse and helps for curly infix are on my [Github](https://github.com/damien-mattei/Scheme-PLUS-for-Racket) and this should be available soon to Racket package system due to delay of update and rebuild the packages.

---

<div class="post-metadata">

### Author: ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)
#### Post date: [August 18, 2025, 10:04am UTC](https://racket.discourse.group/t/melting-prefix-and-infix-expression-with-scheme-for-racket/3802/4 "2025-08-18T10:04:50Z")

</div>

In a thread i can not found again in my history (because i posted so much 😅) i used Qi with Scheme+.  
There was in the discussion with one of the Qi author @countvajhula the need of having the Scheme+ expression parsed by the reader instead of syntax transforming by syntax transformer and macros before running.  
This is now normally done in the latest releases of scheme+ version 11.0 and SRFI-105 curly infix reader version 11.0 that are on my github account and should be synced with racket package as soon as the package system did it.I can not test it now with Qi.

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [August 27, 2025, 4:08am UTC](https://racket.discourse.group/t/melting-prefix-and-infix-expression-with-scheme-for-racket/3802/5 "2025-08-27T04:08:11Z")

</div>

That's great news. I don't recall the exact discussion either, but doing the infix-\>prefix syntax translation at the reader stage sounds like a robust and unambiguous approach! Congrats on completing all of this work --- sounds like there are a lot of interesting features being added in Scheme+. I'm looking forward to trying it out one of these days 👍
