On Feb 4, 2008 11:43 PM, David A. Wheeler <[EMAIL PROTECTED]> wrote: > Alan Manuel Gloria: > > However, having a rule about whether it ends up hooking into a macro > > will then mean having an additional rule that has to be remembered by > > the user of the new reader, as well as possibly the user of any macro > > that has to do scanning of that type. So I propose that either the > > reader completely handles infix, or it completely ignores it - no > > in-between. > > I normally write code so that the macro is never invoked. You do, but will the end users do too?
> > > #|Assumes existing functions: > > (bracketaccess-generic obj &rest dimensions) > > - accesses a dimensioned object; the number of dimensions > > given must match the number of dimensions in the actual object > > (get-number-of-dimensions obj) > > - determines the number of dimensions in the obj > > |# > > (define (bracketaccess o d) > > (cond > > ( (listp o) > > (if (eq (get-number-of-dimensions (car o)) (length o)) > > (apply #'bracketaccess-generic (append o (list d))) > > (append o (list d)) )) > > ( (neq 1 (get-number-of-dimensions obj)) > > (list o d) ) > > ( t > > (bracketaccess-generic o d) ))) > > #|Creating a congruent setf-macro is left as an exercise to the reader|# > > > > In the above untested sample, the bracketaccess function never > > actually "reaches in" the object except at the final bracketaccess > > Except that get-number-of-dimensions _does_ need to do a slight reach-in. > That's because "a[x][y]" in sweet-expressions maps to: > (bracketaccess (bracketaccess a x) y) > and so on. Yes, and that's what the code above handles. If we were to define a particular get-number-of-dimensions method for arrays: #|Warning: not sure. I'm a complete CLOS noob. read at your own risk|# (defmethod (get-number-of-dimensions (a array)) (length (array-dimensions a)) ) So for two-dimensional arrays, array-dimensions returns a list of two integers, whose length we then measure. This is pretty much all the reaching-in necessary. For hash tables we could just have it return a 1: (defmethod (get-number-of-dimensions (h hash-table)) 1) In fact, for any generic type g (except lists, because we're using them to hold the curried bracketaccess), we need only to define methods for get-number-of-dimensions and bracketaccess-generic on g to be able to handle that type in a nested bracketaccess. Alternatively we could just switch over to Arc, which I hear is an automatically currying language ^^. Sincerely, AmkG ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss