hello,
i'm porting SRFI 105 "Curly infix" to Racket.
I wrote a "reader" that works and the SRFI 105 is packaged with a REPL that works already with little change (only one line modified as far as ia can remember) but i'm facing a difficulty, being not easy with the Racket ecosytem of building lanaguages:
-first how can i make my implementation parse, not only the main program, but possibly include files? i.e if i have a (include "infix-file.scm") i want the reader/parser to load and parse it before the expansion step whch is too late and more difficult
here the beginning of my specialised code (the rest is as the official SRFI 105) file SRFI-105.rkt:
#lang racket
(require syntax/strip-context)
(provide (rename-out [literal-read read]
[literal-read-syntax read-syntax]))
(define (literal-read in)
(syntax->datum
(literal-read-syntax #f in)))
(define (literal-read-syntax src in)
(define lst-code (process-input-code-rec in))
`(module anything racket ,@lst-code))
;; read all the expression of program
;; a tail recursive version
(define (process-input-code-tail-rec in) ;; in: port
(define (process-input acc)
(define result (curly-infix-read in)) ;; read an expression
(if (eof-object? result)
(reverse acc)
(process-input (cons result acc))))
(process-input '()))
; ------------------------------
; Curly-infix support procedures
; ------------------------------
and here is an example of source file using it:
#lang reader "SRFI-105.rkt"
(- (+ 3 3)
{2 + 2})
{5 + 2}
(define (fibonacci n)
(if (< n 2)
n
(+ (fibonacci (- n 1)) (fibonacci (- n 2)))))
(fibonacci 7)
(define (fib n)
(if {n < 2}
n
{(fib {n - 1}) + (fib {n - 2})} ))
(fib 11)
and the obvious results:
Welcome to DrRacket, version 8.2 [cs].
Language: reader "SRFI-105.rkt", with debugging; memory limit: 128 MB.
2
7
13
89
>
-second, i know how to make a #lang "my language.rkt" parse the following code but i do not know how to integrate the working SRFI 105 REPL in Racket ecosystem (for now it works in a separate file than parser).
here the official SRFI 105 that already work in Racket with minor changes:
; --------------
; Demo of reader
; --------------
(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))
;{1 + 1}
;(+ 1 1)
;2
;(define k {1 + 1})
;(define k (+ 1 1))
;#<void>
;k
;k
;2
; repeatedly read in curly-infix and write traditional s-expression.
(define (process-input)
(let ((result (curly-infix-read)))
(cond ((not (eof-object? result))
(let ((rv (eval result ns)))
(write result) (display "\n")
(write rv)
(display "\n"))
;; (force-output) ; flush, so can interactively control something else
(process-input)) ;; no else clause or other
)))
(process-input)
by the way Racket Discourse is really cool instead of regular mail for editing and posting code.
Damien