From: Tim Bradshaw
Subject: Re: thoughts on reference chaining and clos
Date: 
Message-ID: <ey38zyr8319.fsf@cley.com>
* Clemens Heitzinger wrote:

> Isn't this prefix versus postfix syntax?  You could write your own
> read macro which translates say {object foo bar baz} into (baz (bar
> (foo obj))).

Something like this?

    (defvar *slip-readtable* (copy-readtable))

    (set-syntax-from-char #\] #\) *slip-readtable* *readtable*)

    (set-macro-character #\[
			 #'(lambda (stream char)
			     (declare (ignore char))
			     (let ((l (read-delimited-list #\] stream t)))
			       (cond ((null (cdr l))
				      l)
				     ((eql (car l) ·@)
				      `#'(lambda () ,@(cdr l)))
				     ((eql (cadr l) ·@)
				      `#'(lambda ,(car l) ,@(cddr l)))
				     (t
				      `(,(cadr l) ,(car l) ,@(cddr l))))))
			 t *slip-readtable*)

    (defun slip-rep ()
      (let ((*readtable* *slip-readtable*)
	    (e '#:EOF))
	(loop
	  (multiple-value-bind (form errorp)
	      (with-simple-restart (continue-slip "Continue SLIP-REP")
		(progn (format t "~&> "))
		(read *standard-input* nil e))
	    (when (eq form e)
	      (return-from slip-rep (values)))
	    (if errorp
		(princ "[Read error]" *error-output*)
		(multiple-value-bind (val errorp)
		    (with-simple-restart (continue-slip "Continue SLIP-REP")
		      (values (eval form)))
		  (if errorp
		      (princ "[Eval error]" *error-output*)
		      (print val *standard-output*))))))))

Except this isn't really right, because it doesn't do the whole
chaining bit:

	[x foo bar]

is

	(foo x bar)

not

	(bar (foo x))

-- I don't know how you do that right and deal with functions with
more than one argument.  Smalltalk copes with this somehow, but I
forget how (does it only have keyword arguments?, that would work
because you can check for KWs in the readmacro.

	[x foo :crun 1 bar :henry 2]

would be

	(bar (foo x :crun 1) :henry 2)

) <- paren on a line on its own!

--tim