[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vectors like functions

Bruce Lewis <brlewis@alum.mit.edu> writes:
> Scheme is known for being concise, but (vector-ref v 0) is not as
> concise as the v[0] syntax in other languages.  I just wanted to note
> that you could make (v 0) work without making vectors be functions.
> Just extend the Scheme semantics to handle a vector in the operator
> position.
> Unfortunately, you can't do exactly that with Scheme macros.

It has long occurred to me that there is no good reason not to create
reader macros in a lisp-like language that would make constructs like
a.b["hi"] work as you might expect.

And yes, I do note that in my example I was using a string as a
subscript -- that notation for things like hash tables is really one
of the few things I like about perl etc.

In this case, imagine a generalized "reference" function that knows
how to take components of structures, arrays, hash tables, etc., much
as setf is a generalized mutator -- call it "ref" for purposes of
discussion. You could then easily translate a.b["hi"] into something
like (ref (ref a b) "hi")

One might ask why this is of use. Sure, it is just sugar, but then
again so is 'a -> (quote a). Another nickel's worth of syntactic sugar
would make it much more convenient to use structured data types of all
sorts, which would probably lead to more use of them.

Perry E. Metzger		perry@piermont.com