[Top][All Lists]

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

Re: procedure-source availability

From: Panicz Maciej Godek
Subject: Re: procedure-source availability
Date: Sun, 7 Oct 2012 02:07:20 +0200


> 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
(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)

(where ``lexical-names'' returns the car-s of ``lexicals'', as defined
at the bottom of

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)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]