Newsgroups: comp.lang.scheme.scsh
Subject: Arc a la carte
From: walter@pelissero.org (Walter C. Pelissero)
Message-ID: <86r8o67525.fsf@hyde.lpds.sublink.org>
Date: 31 Jan 2002 18:23:30 +0000
After reading http://www.paulgraham.com/arc.html I wasn't left very
impressed especially because most of that can be achieved with macros
in Common Lisp.
Nevertheless there was a feature I found cool. The square bracket
sexp that expands to a single argument lambda expression. So that I
can do things like:
(map [/ _ 2] '(2 4 6 8 10))
(cond ((regexp-exec r) => [match:substring _ 1]) ...)
instead of
(map (lambda (x) (/ x 2)) '(2 4 6 8 10))
(cond ((regexp-exec r) => (lambda (m) (match:substring m 1))) ...)
After a few minutes of searching I found out that Scheme48 has
surprising similarities with CL when it comes to syntax macros.
So here is the trick:
--- /usr/home/wcp/Projects/others-cvs/scsh/scsh/scsh/scsh-read.scm Fri Aug 6 14:28:02 1999
+++ scsh/scsh-read.scm Thu Jan 31 17:40:09 2002
@@ -29,6 +29,15 @@
(define-sharp-macro #\! script-skip)
+;;; Arc à la carte
+(set-standard-read-macro! #\[ #t
+ (lambda (c port)
+ (list 'lambda '(_) (sub-read-list c port))))
+(set-standard-read-macro! #\] #t
+ (lambda (c port)
+ c port
+ close-paren))
+
;;; Readme and readme are distinct symbols.
I'm not suggesting Scsh or Scheme48 to pick up this syntactic sugar
nor I wish Scheme would fall, together with Perl, in the hell of
syntactic crypticism. This has been written just as a funny exercise
in Scsh hacking and... Arc mocking, of course. On the other hand I
wish this sort of things were be possible without patching Scsh (or
Scheme48).
--
walter pelissero
http://www.pelissero.de
Up |