Re: [r6rs-discuss] [Formal] please make square brackets more useful
Sam TH wrote:
> Finally, the R6RS has admirably refrained from specifying too many
> proposals that had not previously been implemented, and that the
> community has no experience with.
LOL!
> Your and Jonathan's proposal would add another instance of this.
No, Jonathan proposed something whose essentials have
been implemented many times, by many different people,
for many different purposes. The Lisp community has a
lot of experience with this, even if some Schemers don't.
Will
; An example of syntactic extension via square brackets.
;
; Other examples, such as making [proc arg1 ...] equivalent to
; a procedure call that is guaranteed to evaluate its arguments
; from left to right, or allowed to evaluate them in parallel,
; are left as an exercise for the (no pun intended) reader.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This lexical customization uses facilities that have been
; provided by MacScheme and by Larceny up through v0.93.
; Many other systems have provided similar facilities.
;
; This code will not work in Larceny v0.94 (Doomsday Device),
; because v0.94 implements the lexical syntax proposed for
; R6RS, and the R6RS lexical syntax is so complex that the
; customization facilities had to be dropped, at least for
; Doomsday Device.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(let* ((lparen-reader (readtable-ref #\())
(lparen-class (car lparen-reader))
(lparen-dispatch (cadr lparen-reader))
(lparen-dispatch-list (caddr lparen-reader))
(rparen-reader (readtable-ref #\())
(rparen-class (car rparen-reader))
(rparen-dispatch (cadr rparen-reader))
(rparen-dispatch-list (caddr rparen-reader)))
(readtable-set! #\[
(list lparen-class
(lambda args
(cons '*square-bracketed*
(apply lparen-dispatch args)))
lparen-dispatch-list))
(readtable-set! #\]
(list rparen-class
(lambda args (error #f errormsg))
(lambda args '()))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Example 1.
;
; If e1 and e2 are expressions that evaluate to exact integers
; m and n, then [e1 __ e2] is an expression that evaluates to
; the ordered list of integers i such that (<= m i n).
;
; Example: [(sqrt 100) __ (expt 2 4)] => (10 11 12 13 14 15 16)
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-syntax *square-bracketed*
(syntax-rules (__)
((_ e1 __ e2)
(let ((m e1) (n e2))
(do ((n n (- n 1))
(result '() (cons n result)))
((> m n) result))))))
; end of example 1
Received on Wed Jun 20 2007 - 11:42:51 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:01 UTC