unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guile-user@gnu.org
Subject: Re: procedure-source availability
Date: Sun, 7 Oct 2012 02:07:20 +0200	[thread overview]
Message-ID: <CAMFYt2bYd1cOJT0JACywBXxs4_VzUxN1M=B-MzS8AJ9kbsHEDQ@mail.gmail.com> (raw)
In-Reply-To: <87txuakouv.fsf@gnu.org>

Howdie

> Instead of storing actual code that recreates the GUI, how about storing
> high-level declarations that describe that GUI?
[...]

Well, the problem is that I don't yet know what I am doing, so I'm
trying to keep the system as general as possible. One of the features
that is certainly going to be needed anyway, is a way to store and
restore lambdas, because this is the essential abstraction mechanism
of Scheme. Maybe some separate layer for GUI description will emerge
later on, but the task that I assigned to myself seems worth exploring

>> I recall someone having the idea of adding smalltalk-like images to guile.
>> I'd love to see such feature one day, but if guile is supposed to be
>> an extension language, I think the C interface would need to be
>> redesigned, because there would be a need to somehow dump the smobs
>> from the heap to re-load them later.
>
> At the C level, that seems somewhat ambitious.  :-)

Yep. :)

>> I don't know much about the implementation of the GOOPS objects, but I
>> suspect that they would also require some means of serialization
>
> The (oop goops save) module implements parts of a serialization
> framework.  When GOOPS is loaded, any Scheme object is a GOOPS instance,
> so one could define methods to serialize any type of object.

It looks interesting, but I somehow can't get it to run, even for very
simple cases:
> (use-modules (oop goops) (oop goops save))
> (save-objects '((a . 1)(b . 2)) (current-output-port))
(define a '1)
(define b '2)
ERROR: In procedure hashq-get-handle:
ERROR: In procedure hashq-get-handle: Handle access not permitted on weak table

> (version)
$1 = "2.0.5-deb+1-1"

Besides this, it looks similar to the thing I'm working on, so if I
get far enough, then perhaps my results could be incorporated into
that framework? (It requires some labour though, as there are many
types to be considered

>> then I could easily implement this functionality myself (making 'self'
>> a reserved keyword)
>>
>> (define-syntax lambda
>>   (syntax-rules ()
>>     ((_ args body ...)
>>      (let ((self (primitive-lambda args body ...)))
>>        (set-procedure-property! self 'source (quote (primitive-lambda
>> args body ...)))
>>        self))))
>
> Note that this doesn’t make ‘self’ a reserved keyword; instead, it’s
> just a local variable that cannot be referred to by name in BODY, thanks
> to the macro hygiene rules.

Yes, you're right.
I even went a little further with that and now I also capture lexical
environment:
(use-modules (system syntax) (ice-9 local-eval))

(define-macro (function args . body)
  `(let ((environment (the-environment))
         (lexical-names (lexical-names))
         (procedure (lambda ,args ,@body)))
     (set-procedure-property! procedure 'source '(function ,args ,@body))
     (set-procedure-property! procedure 'environment environment)
     (set-procedure-property! procedure 'lexical-names lexical-names)
     procedure))

(where ``lexical-names'' returns the car-s of ``lexicals'', as defined
at the bottom of
http://www.gnu.org/software/guile/manual/html_node/Syntax-Transformer-Helpers.html#Syntax-Transformer-Helpers
)

So in addition to the source of the procedure, the lexical environment
can also be retrieved:

(define (procedure-lexicals proc)
  (map (lambda(symbol)
         (cons symbol
               (local-eval symbol (procedure-property proc 'environment))))
   (procedure-property proc 'lexical-names)))

The strange thing was that I had to define the macro ``function''
using define-macro -- the define-syntax counterpart for some reason
wouldn't work. So for example, if I wrote
(define f (let ((y 5)) (function x (set! y (apply + y x)) y))
then if ``function'' was defined by means of define-syntax/syntax-rules, ie

(define-syntax function
  (syntax-rules ()
    ((_ args body ...)
     (let ((environment (the-environment))
           (lexical-names (lexical-names))
           (procedure (lambda args body ...)))
       (set-procedure-property! procedure 'source '(function args body ...))
       (set-procedure-property! procedure 'environment environment)
       (set-procedure-property! procedure 'lexical-names lexical-names)
       procedure))))

then the ``environment'' variable wouldn't capture the ``y'' (or
anything else, for that matter). I find that kinda weird, so I'm
sharing my doubts. Fortunately, the define-macro version behaves as
one could expect, so I can move on with my work

Thanks&regards
Maciek



  reply	other threads:[~2012-10-07  0:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-23 19:05 procedure-source availability Panicz Maciej Godek
2012-09-30 20:11 ` Panicz Maciej Godek
2012-10-01  3:40   ` Mark H Weaver
2012-10-01 16:31     ` Panicz Maciej Godek
2012-10-02 14:06       ` Ludovic Courtès
2012-10-02 19:29         ` Panicz Maciej Godek
2012-10-03  1:03           ` Daniel Hartwig
2012-10-03 16:27             ` Panicz Maciej Godek
2012-10-04 19:40               ` Ludovic Courtès
2012-10-07  0:07                 ` Panicz Maciej Godek [this message]
2012-10-07 20:36                   ` Ludovic Courtès
2012-10-08 20:11                     ` Panicz Maciej Godek
2012-10-08 17:57                   ` Mark H Weaver
2012-10-04 16:16           ` Ludovic Courtès

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='CAMFYt2bYd1cOJT0JACywBXxs4_VzUxN1M=B-MzS8AJ9kbsHEDQ@mail.gmail.com' \
    --to=godek.maciek@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=ludo@gnu.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.
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).