From: Tim Bradshaw
Subject: Re: Making structures useable
Date: 
Message-ID: <cghqnh$d5l@odah37.prod.google.com>
M Jared Finder wrote:

>
> This seems like something that people must have solved previously (or

> perhaps there is a solution in the standard).  That is why I would
like
> your input.  I need feedback from people who have written big
projects
> and therefore must have run into this problem before.


Using SYMBOL-MACROLET it is fairly easy to write a macro like this:

(with-shorthand-accessors (ob (left x-left-griblle) (right
x-right-gribble))
(setf left (+ 1 2)
right (+ right 4)))

Which translates to the equivalent of:

(setf (x-left-gribble ob) (+ 1 2)
(x-right-gribble ob) (+ (x-right-gribble ob) 4))

Then you can write shorthand macros for any structure type using this
macro.

The implementation is left to the reader (or in other words, I don't
have a lisp environment to hand).

--tim

From: Thomas Schilling
Subject: Re: Making structures useable
Date: 
Message-ID: <opsdadv9oitrs3c0@news.CIS.DFN.DE>
Wrote schrieb Tim Bradshaw <··········@tfeb.org>:

> Using SYMBOL-MACROLET it is fairly easy to write a macro like this:
>
> (with-shorthand-accessors (ob (left x-left-griblle) (right
> x-right-gribble))
> (setf left (+ 1 2)
> right (+ right 4)))
>
> Which translates to the equivalent of:
>
> (setf (x-left-gribble ob) (+ 1 2)
> (x-right-gribble ob) (+ (x-right-gribble ob) 4))
>
> Then you can write shorthand macros for any structure type using this
> macro.
>
> The implementation is left to the reader (or in other words, I don't
> have a lisp environment to hand).

(defmacro with-shorthand-accessors ((obj &rest binds) &body body)
   (let ((ob (gensym)))
     `(let ((,ob ,obj))
       (symbol-macrolet
	  ,(mapcar (lambda (x)
		     `(,(first x) (,(second x) ,ob)))
		   binds)
	,@body))))

-- 
      ,,
     \../   /  <<< The LISP Effect
    |_\\ _==__
__ | |bb|   | _________________________________________________
From: Marco Baringer
Subject: Re: Making structures useable
Date: 
Message-ID: <m2zn4jo14x.fsf@convey.it>
"Tim Bradshaw" <··········@tfeb.org> writes:

> Using SYMBOL-MACROLET it is fairly easy to write a macro like this:
>
> (with-shorthand-accessors (ob (left x-left-griblle) (right x-right-gribble))
>   (setf left (+ 1 2)
>         right (+ right 4)))

or just use with-accessors.

(with-accessors ((left x-left-griblle) 
                (right x-right-gribble))
    obj
  (setf left (+ 1  2)
        right (+ right 4)))

-- 
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
     -Leonard Cohen