all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Toby Cubitt <tsc25@cantab.net>
To: help-gnu-emacs@gnu.org
Subject: Re: Writing a function/macro in Elisp that generates a function at runtime
Date: Tue, 28 Oct 2008 13:42:57 +0100	[thread overview]
Message-ID: <490708D1.4070906@dr-qubit.org> (raw)
In-Reply-To: <4906EB9C.10501@dr-qubit.org>

Toby Cubitt wrote:
> Barry Margolin wrote:
>> You don't need to generate a function on the fly for this.  Do something 
>> like this:
>>
>> (defun insert-with-function (insfun new-data old-cell)
>>   (setf (cell-data old-cell)
>>         (funcall insfun new-data (cell-data old-cell)))
>>   old-cell)
> 
> Hmmmm...the simplest ideas are always best. This does sound like a
> better approach. Thanks!

I've now remembered why this won't work, at least not straightforwardly.

I have a higher-level data structure built on top of a lower-level one.
Internally, the higher-level structure stores data "cells" in the
lower-level structure. The lower-level structure of course knows nothing
about this. It just stores any kind of data, without knowing anything
about its structure. And users of the higher-level structure also know
nothing about the data cells, which are part of the internal
implementation. As far as users are concerned, they can just store data
of whatever kind they like in the higher-level structure.

For the lower-level structure, I have defined exactly this kind of
insert-with-function, called say `low-level-insert-with-function'. What
I'm trying to do is to define a `high-level-insert-with-function' for
the higher-level data structure. Clearly, it has to call
`low-level-insert-with-function' to insert the data into the lower-level
structure on which it is build, something like:

(defun high-level-insert-with-function (higher-structure data insfun)
  (low-level-insert-with-function
   (higher-structure--get-lower-structure higher-structure)
   data ??insfun??))

Now insfun knows nothing about the data cells, since it was passed in by
the user. And `low-level-insert-with-function' knows nothing about data
cells, since it acts on the lower-level data structure.

So it would seem I need to wrap insfun on the fly in the above function,
to make it aware that the data is actually stored within "cells". And
we're back to the problem from my previous mail: how to generate a
wrapped insfun on the fly, in such a way that the setf macro required to
enter data into a "cell" is expanded into the cell-data accessor
function at compile-time.

I still don't see why this should be fundamentally impossible. The
function can easily be generated on the fly by a backquote construct (as
in my first attempt), and all the necessary information for
macro-expanding setf is there at compile-time. It's 'just' a question of
getting macro-expansion to be carried out within the backquote construct
(which is what I was trying in my second attempt).

Probably there's a different way of approaching the problem that I'm not
seeing.

Thanks for your help (and sorry for the lengthy explanation),

Toby




  reply	other threads:[~2008-10-28 12:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.2216.1225168079.25473.help-gnu-emacs@gnu.org>
2008-10-28  5:56 ` Writing a function/macro in Elisp that generates a function at runtime Barry Margolin
2008-10-28 10:38   ` Toby Cubitt
2008-10-28 12:42     ` Toby Cubitt [this message]
     [not found]     ` <mailman.2265.1225201433.25473.help-gnu-emacs@gnu.org>
2008-10-28 16:47       ` Ted Zlatanov
2008-10-28 17:10         ` Toby Cubitt
2008-10-27 13:30 Toby Cubitt
2008-10-28 18:09 ` Johan Bockgård
2008-10-28 17:21   ` Toby Cubitt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=490708D1.4070906@dr-qubit.org \
    --to=tsc25@cantab.net \
    --cc=help-gnu-emacs@gnu.org \
    --cc=toby-dated-1225633381.69f9a3@dr-qubit.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.