unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* define - any name
@ 2003-04-19  7:22 Egil Moeller
  2003-04-20 14:58 ` Andreas Rottmann
  0 siblings, 1 reply; 11+ messages in thread
From: Egil Moeller @ 2003-04-19  7:22 UTC (permalink / raw)


At the moment, I have a function (list-entry type name), that given a
"type-definition" (a binary tree with names in), and a name, constructs a
function that will extract the entity at the position corresponding to
that name in the type, in a binary tree given as argument. The
"type-definition" i often constructed from other such definitions:

(define fride-vote-msg-type
  `(list
    (id:         ,fride-id-msg-type)
    (referendum: ,fride-id-reference-msg-type)
    (date:       int)
    (vote:       int)))

I use the list-entry function, then to construct a set of
"access-functions", e.g.

(define fride-vote-list.id (fride-list-entry fride-vote-msg-type 'id))
(define fride-vote-list.referendum (fride-list-entry fride-vote-msg-type 'referendum))

This is both quite some extra work, and also makes the code clumsier, than
if those functions could be automatically created. I'd like to write
something like

(define-type fride-vote-msg-type
  `(list
    (id:         ,fride-id-msg-type)
    (referendum: ,fride-id-reference-msg-type)
    (date:       int)
    (vote:       int)))

and have them all created. For this purpose I have created a function that
finds all names in a type-definition that can be used to create such
access-functions.

The question i, how do I go on from here? I'd like to make a macro, but
that would not let the backqoute be evaluated in the correct
environment... What I would need is a (define-unquoted-in-toplevel name
value), that would work like an ordinary funcion, evaluating its
arguments, and bind the value of name to the value of value, in the
top-level surrounding environment... Is this really not something people
have wanted before?

My idea about environments in quile is that they, due to speed
considerations or something, are a bit too limited... For example, an
eval-closure is _not_ an ordinary environment/can't be treated like one,
and one can not do (eval) with such an object as environment...

Regards,
Egil

-- 
http://redhog.org
GPG Public key: http://redhog.org/PGP%20Public%20key.asc
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: define - any name
       [not found] <Pine.LNX.4.30.0304190908110.27066-100000@urd.norna.redhog. org>
@ 2003-04-19 20:27 ` Ken Anderson
  0 siblings, 0 replies; 11+ messages in thread
From: Ken Anderson @ 2003-04-19 20:27 UTC (permalink / raw)
  Cc: guile-user

Olin Shivers taught me the trick that in Scheme, you can write macros in a way that will allow "," to be used to unquote arguments in the macro.

If nothing else you could define a macro, (define-type name fields) that would work something like this:

(define-type
  fride-vote-msg-type
  `((id:         ,fride-id-msg-type)
    (referendum: ,fride-id-reference-msg-type)
    (date:       int)
    (vote:       int)))

But with Olin's style it could look something like:
(define-type
  fride-vote-msg-type
  (id:         ,fride-id-msg-type)
  (referendum: ,fride-id-reference-msg-type)
  (date:       int)
  (vote:       int))

At 09:22 AM 4/19/2003 +0200, Egil Moeller wrote:
>At the moment, I have a function (list-entry type name), that given a
>"type-definition" (a binary tree with names in), and a name, constructs a
>function that will extract the entity at the position corresponding to
>that name in the type, in a binary tree given as argument. The
>"type-definition" i often constructed from other such definitions:
>
>(define fride-vote-msg-type
>  `(list
>    (id:         ,fride-id-msg-type)
>    (referendum: ,fride-id-reference-msg-type)
>    (date:       int)
>    (vote:       int)))
>
>I use the list-entry function, then to construct a set of
>"access-functions", e.g.
>
>(define fride-vote-list.id (fride-list-entry fride-vote-msg-type 'id))
>(define fride-vote-list.referendum (fride-list-entry fride-vote-msg-type 'referendum))
>
>This is both quite some extra work, and also makes the code clumsier, than
>if those functions could be automatically created. I'd like to write
>something like
>
>(define-type fride-vote-msg-type
>  `(list
>    (id:         ,fride-id-msg-type)
>    (referendum: ,fride-id-reference-msg-type)
>    (date:       int)
>    (vote:       int)))
>
>and have them all created. For this purpose I have created a function that
>finds all names in a type-definition that can be used to create such
>access-functions.
>
>The question i, how do I go on from here? I'd like to make a macro, but
>that would not let the backqoute be evaluated in the correct
>environment... What I would need is a (define-unquoted-in-toplevel name
>value), that would work like an ordinary funcion, evaluating its
>arguments, and bind the value of name to the value of value, in the
>top-level surrounding environment... Is this really not something people
>have wanted before?
>
>My idea about environments in quile is that they, due to speed
>considerations or something, are a bit too limited... For example, an
>eval-closure is _not_ an ordinary environment/can't be treated like one,
>and one can not do (eval) with such an object as environment...
>
>Regards,
>Egil
>
>-- 
>http://redhog.org
>GPG Public key: http://redhog.org/PGP%20Public%20key.asc
>Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
>
>
>
>_______________________________________________
>Guile-user mailing list
>Guile-user@gnu.org
>http://mail.gnu.org/mailman/listinfo/guile-user



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: define - any name
  2003-04-19  7:22 define - any name Egil Moeller
@ 2003-04-20 14:58 ` Andreas Rottmann
  2003-04-21 17:22   ` Egil Moeller
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Rottmann @ 2003-04-20 14:58 UTC (permalink / raw)
  Cc: guile-user

Egil Moeller <redhog@redhog.org> writes:

> At the moment, I have a function (list-entry type name), that given a
> "type-definition" (a binary tree with names in), and a name, constructs a
> function that will extract the entity at the position corresponding to
> that name in the type, in a binary tree given as argument. The
> "type-definition" i often constructed from other such definitions:
> 
> (define fride-vote-msg-type
>   `(list
>     (id:         ,fride-id-msg-type)
>     (referendum: ,fride-id-reference-msg-type)
>     (date:       int)
>     (vote:       int)))
> 
> I use the list-entry function, then to construct a set of
> "access-functions", e.g.
> 
> (define fride-vote-list.id (fride-list-entry fride-vote-msg-type 'id))
> (define fride-vote-list.referendum (fride-list-entry fride-vote-msg-type 'referendum))
> 
> This is both quite some extra work, and also makes the code clumsier, than
> if those functions could be automatically created. I'd like to write
> something like
> 
> (define-type fride-vote-msg-type
>   `(list
>     (id:         ,fride-id-msg-type)
>     (referendum: ,fride-id-reference-msg-type)
>     (date:       int)
>     (vote:       int)))
> 
> and have them all created. For this purpose I have created a function that
> finds all names in a type-definition that can be used to create such
> access-functions.
> 
I think you can get this easier with GOOPs - have a look at its
setters and getters concept...

Regards, Andy
-- 
Andreas Rottmann         | Rotty@ICQ      | 118634484@ICQ | a.rottmann@gmx.at
http://www.8ung.at/rotty | GnuPG Key: http://www.8ung.at/rotty/gpg.asc
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62

Python is executable pseudocode, Perl is executable line-noise.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: define - any name
  2003-04-20 14:58 ` Andreas Rottmann
@ 2003-04-21 17:22   ` Egil Moeller
  2003-04-21 23:46     ` dvanhorn
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Egil Moeller @ 2003-04-21 17:22 UTC (permalink / raw)


After some digging in the not-so-very-good guile documentation, I found
local-eval. That's a good one. And it solves my problem fine:

guile> (define
  quasieval
  (procedure->macro
   (lambda (code env)
     (local-eval (list 'quasiquote (cdr code)) env))))
guile> (define y 'foo)
guile> (quasieval define ,y 'zzg)
guile> foo
zzg
guile>


Hm, how do one submit an SRFI? I think my quasieval could be of use by
others too, if it does not allready exist somewhere out there...

-- 
http://redhog.org
GPG Public key: http://redhog.org/PGP%20Public%20key.asc
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: define - any name
  2003-04-21 17:22   ` Egil Moeller
@ 2003-04-21 23:46     ` dvanhorn
  2003-04-26 11:10     ` Neil Jerram
  2003-05-03 23:41     ` Marius Vollmer
  2 siblings, 0 replies; 11+ messages in thread
From: dvanhorn @ 2003-04-21 23:46 UTC (permalink / raw)
  Cc: guile-user

Quoting Egil Moeller <redhog@redhog.org>:
 
> Hm, how do one submit an SRFI? I think my quasieval could be of use by
> others too, if it does not allready exist somewhere out there...

   http://srfi.schemers.org/srfi-process.html

-d




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: define - any name
  2003-04-21 17:22   ` Egil Moeller
  2003-04-21 23:46     ` dvanhorn
@ 2003-04-26 11:10     ` Neil Jerram
  2003-05-03 23:30       ` Marius Vollmer
  2003-05-03 23:41     ` Marius Vollmer
  2 siblings, 1 reply; 11+ messages in thread
From: Neil Jerram @ 2003-04-26 11:10 UTC (permalink / raw)
  Cc: guile-user

>>>>> "Egil" == Egil Moeller <redhog@redhog.org> writes:

    Egil> After some digging in the not-so-very-good guile
    Egil> documentation, I found local-eval. That's a good one. And it
    Egil> solves my problem fine:

If you have time to write a doc patch that would have made your
digging easier, I'd be happy to apply it.

Regards,
        Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: define - any name
  2003-04-26 11:10     ` Neil Jerram
@ 2003-05-03 23:30       ` Marius Vollmer
  0 siblings, 0 replies; 11+ messages in thread
From: Marius Vollmer @ 2003-05-03 23:30 UTC (permalink / raw)
  Cc: guile-user

Neil Jerram <neil@ossau.uklinux.net> writes:

> >>>>> "Egil" == Egil Moeller <redhog@redhog.org> writes:
> 
>     Egil> After some digging in the not-so-very-good guile
>     Egil> documentation, I found local-eval. That's a good one. And it
>     Egil> solves my problem fine:
> 
> If you have time to write a doc patch that would have made your
> digging easier, I'd be happy to apply it.

Hmm, I'd rather not recommend 'local-eval' for anything other than
writing debuggers.  Egil's quasieval is a strange animal that mixes
run-time and compile-time environments that we don't want to support.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: define - any name
  2003-04-21 17:22   ` Egil Moeller
  2003-04-21 23:46     ` dvanhorn
  2003-04-26 11:10     ` Neil Jerram
@ 2003-05-03 23:41     ` Marius Vollmer
  2003-05-04 19:52       ` [ot] " rm
  2003-05-04 20:18       ` Marius Vollmer
  2 siblings, 2 replies; 11+ messages in thread
From: Marius Vollmer @ 2003-05-03 23:41 UTC (permalink / raw)
  Cc: guile-user

Egil Moeller <redhog@redhog.org> writes:

> guile> (define
>   quasieval
>   (procedure->macro
>    (lambda (code env)
>      (local-eval (list 'quasiquote (cdr code)) env))))
> guile> (define y 'foo)
> guile> (quasieval define ,y 'zzg)
> guile> foo
> zzg
> guile>
> 
> Hm, how do one submit an SRFI? I think my quasieval could be of use by
> others too, if it does not allready exist somewhere out there...

Oops, that a strange thing you are doing here.  You can't count on
macro expansion to happen at a specific time.  For example, 'foo'
doesn't need to be defined when the quasieval macro is expanded.

In general, 'local-eval' should be avoided like the plaque as it
destroys the important property of Scheme that lexical environments
are fixed at compile time.

Top-level environments (aka modules) can be changed at run-time.  When
ordinary macros and 'define' is not enough, you can use
'module-define!':

  guile> (define y 'foo)
  guile> (module-define! (current-module) y 'zzg)
  guile> foo
  zzg

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ot] Re: define - any name
  2003-05-03 23:41     ` Marius Vollmer
@ 2003-05-04 19:52       ` rm
  2003-05-04 20:24         ` Marius Vollmer
  2003-05-04 20:18       ` Marius Vollmer
  1 sibling, 1 reply; 11+ messages in thread
From: rm @ 2003-05-04 19:52 UTC (permalink / raw)
  Cc: redhog

On Sun, May 04, 2003 at 01:41:09AM +0200, Marius Vollmer wrote:
> 
> In general, 'local-eval' should be avoided like the plaque as it

Are you a dentist, by any chance? 

 Ralf Mattes :-)))


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: define - any name
  2003-05-03 23:41     ` Marius Vollmer
  2003-05-04 19:52       ` [ot] " rm
@ 2003-05-04 20:18       ` Marius Vollmer
  1 sibling, 0 replies; 11+ messages in thread
From: Marius Vollmer @ 2003-05-04 20:18 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer <mvo@zagadka.de> writes:

> When ordinary macros and 'define' is not enough, you can use
> 'module-define!':

Or, of course and more portable, you can use 'eval':

    (eval `(define ,y 'zzg) (interaction-environment))

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ot] Re: define - any name
  2003-05-04 19:52       ` [ot] " rm
@ 2003-05-04 20:24         ` Marius Vollmer
  0 siblings, 0 replies; 11+ messages in thread
From: Marius Vollmer @ 2003-05-04 20:24 UTC (permalink / raw)
  Cc: guile-user

rm@fabula.de writes:

> On Sun, May 04, 2003 at 01:41:09AM +0200, Marius Vollmer wrote:
> > 
> > In general, 'local-eval' should be avoided like the plaque as it
>
> Are you a dentist, by any chance? 

:-))  Took me a while to get this.  With my font, this is a 3-pixel-typo. ;)

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-05-04 20:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-19  7:22 define - any name Egil Moeller
2003-04-20 14:58 ` Andreas Rottmann
2003-04-21 17:22   ` Egil Moeller
2003-04-21 23:46     ` dvanhorn
2003-04-26 11:10     ` Neil Jerram
2003-05-03 23:30       ` Marius Vollmer
2003-05-03 23:41     ` Marius Vollmer
2003-05-04 19:52       ` [ot] " rm
2003-05-04 20:24         ` Marius Vollmer
2003-05-04 20:18       ` Marius Vollmer
     [not found] <Pine.LNX.4.30.0304190908110.27066-100000@urd.norna.redhog. org>
2003-04-19 20:27 ` Ken Anderson

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