From: "Maciek Godek" <pstrychuj@gmail.com>
To: "Kjetil S. Matheussen" <k.s.matheussen@notam02.no>
Cc: guile-user@gnu.org
Subject: Re: Closure?
Date: Tue, 15 Jul 2008 00:46:57 +0200 [thread overview]
Message-ID: <e2ceda030807141546k27bf98e5k2a003ab8d62fcbf9@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0807142318050.5269@ttleush>
>> This certainly looks like trashing global namespace
>> (which isn't good in the long run) and doesn't allow you
>> to have object handlers (like many variables referring
>> to the same object) without additional quirks.
>>
>
> It's just an example of what local-eval can
> be good for. It's an example of a _namespace
> system_, and not an _OO system_.
OK, sorry, I didn't understand at first.
>>> But for implementing a message passing OO system,
>>> it's easier to use macros and hash tables, plus
>>> that it probably performs much better:
>>
>> Pefrorms better than local-eval or better than
>> define-namespace?
>>
>
> It's much faster than local-eval since it's not
> calling eval for each method call. The overhead of calling
> a method in an OO system, based on hash tables
> and macros, is basically just the time it takes looking
> up the address of the function from
> a hash-table. For guile, which has a large
> overhead already, your program probably won't
> go any slower doing this compared to calling
> functions directly:
Is local-eval much slower than the usual eval?
It is very probable that I get something wrong
right now, but according to my imagination of
a possible implementation :D of eval it could be
the same function (and the closure would
actually be implemented as a hash table or
something like that).
And eval is actually what lisp is doing all the
time, so the only thing that changes here
is the scope (=reference to a hash table)
That's how, I believe, it could be implemented.
(but I've never tried to do that nor read it in the code,
so I'm just being a smart ass)
> (define (make-bank sum)
> (let ((attributes (make-hash-table)))
> (define dispatcher
> (lambda (which . rest)
> (apply (hashq-ref attributes which) rest)))
> (hashq-set! attributes 'sum (lambda ()
> sum))
> (hashq-set! attributes 'add (lambda (n)
> (set! sum (+ n sum))))
> dispatcher))
>
> (define bank (make-bank 0))
> (bank 'add 2)
> (bank 'sum)
> => 2
>
>
> And by using some macros, you can make the syntax look
> much prettier.
To me it already looks very pretty (and works just
as efficiently as my imagination of local-eval operation :>).
This might be just what I've been looking for.
Thanks a lot.
>> Well, I've read some documentation of GOOPS and then
>> I took a glimpse at its source. It has at least a few
>> disadvantages, for it is an object system implemented in
>> scheme -- it is therefore hard to access its objects from C
>> (while closures are easily accessible through
>> scm_local_eval) and it probably won't run as fast as
>> local-eval, at least conceptually.
>>
>
> local-eval is forced to interpret its argument, and is therefore, at least
> conceptually, very slow. I very much doubt GOOPS is that slow,
> but I don't know how GOOPS is implemented though. :-)
Neither do I (I just saw a lot of code, many many layers of code
so I've concluded that it is a complex multi-layer system I don't
want to get into). I never realized that eval causes such terrible
overheads ((procedure-source eval) doesn't show any of the
mysteries of the universe :P)
next prev parent reply other threads:[~2008-07-14 22:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cmu-lmtpd-15105-1216051603-3@mail-imap1.uio.no>
2008-07-14 16:30 ` Closure? Kjetil S. Matheussen
2008-07-14 21:14 ` Closure? Maciek Godek
[not found] ` <e2ceda030807141414i5acef7d1h37d12d14e01cc1d@mail.gmail.com>
2008-07-14 21:41 ` Closure? Kjetil S. Matheussen
2008-07-14 22:46 ` Maciek Godek [this message]
[not found] <cmu-lmtpd-26382-1215792454-10@mail-imap1.uio.no>
2008-07-11 17:42 ` Closure? Kjetil S. Matheussen
2008-07-11 17:47 ` Closure? Kjetil S. Matheussen
2008-07-11 20:54 ` Closure? Maciek Godek
2008-07-12 11:47 ` Closure? Kjetil S. Matheussen
2008-07-13 6:59 ` Closure? Maciek Godek
2008-07-12 22:43 ` Closure? Neil Jerram
2008-07-15 7:59 ` Closure? Ludovic Courtès
2008-07-15 9:11 ` Closure? Andy Wingo
2008-07-16 16:42 ` Closure? Ludovic Courtès
2008-07-11 14:48 Closure? Maciek Godek
2008-07-11 15:01 ` Closure? Ludovic Courtès
2008-07-11 15:32 ` Closure? Maciek Godek
2008-07-12 22:57 ` Closure? Neil Jerram
2008-07-13 6:57 ` Closure? Maciek Godek
2008-07-13 22:56 ` Closure? Neil Jerram
2008-07-14 1:15 ` Closure? Maciek Godek
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e2ceda030807141546k27bf98e5k2a003ab8d62fcbf9@mail.gmail.com \
--to=pstrychuj@gmail.com \
--cc=guile-user@gnu.org \
--cc=k.s.matheussen@notam02.no \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).