From: Karol Skocik
Subject: how to create local defstructs?
Date: 
Message-ID: <1173829256.355594.102390@n76g2000hsh.googlegroups.com>
Hi,
  is there any way to create something like defstruct, in the fashion
of flet for example, where when you go out of scope the definition
disappears?

like:

(letstruct ((struct (slot-1 slot-2 slot-3)))
		  (+ (struct-slot-1 struct-slot-2 struct-slot-3)))

Thanks for any ideas...
  Karol

From: Karol Skocik
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <1173829633.892967.192140@d57g2000hsg.googlegroups.com>
On Mar 14, 12:40 am, "Karol Skocik" <············@gmail.com> wrote:
> Hi,
>   is there any way to create something like defstruct, in the fashion
> of flet for example, where when you go out of scope the definition
> disappears?
>
> like:
>
> (letstruct ((struct (slot-1 slot-2 slot-3)))
>                   (+ (struct-slot-1 struct-slot-2 struct-slot-3)))
>
> Thanks for any ideas...
>   Karol

eh, wrong example :)

something like this would be more correct:

(letstruct ((struct (slot-1 slot-2 slot-3)))
		  (let ((s (make-struct 10 20 30)))
			(with-slots (slot-1 slot-2 slot-3) s
		      (+ (struct-slot-1 struct-slot-2 struct-slot-3)))))
From: Rainer Joswig
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <joswig-22B24B.12364514032007@news-europe.giganews.com>
In article <························@d57g2000hsg.googlegroups.com>,
 "Karol Skocik" <············@gmail.com> wrote:

> On Mar 14, 12:40 am, "Karol Skocik" <············@gmail.com> wrote:
> > Hi,
> >   is there any way to create something like defstruct, in the fashion
> > of flet for example, where when you go out of scope the definition
> > disappears?
> >
> > like:
> >
> > (letstruct ((struct (slot-1 slot-2 slot-3)))
> >                   (+ (struct-slot-1 struct-slot-2 struct-slot-3)))
> >
> > Thanks for any ideas...
> >   Karol
> 
> eh, wrong example :)
> 
> something like this would be more correct:
> 
> (letstruct ((struct (slot-1 slot-2 slot-3)))
> 		  (let ((s (make-struct 10 20 30)))
> 			(with-slots (slot-1 slot-2 slot-3) s
> 		      (+ (struct-slot-1 struct-slot-2 struct-slot-3)))))

If you are desperate to have something similar, you
could use closures. The local variables are the slots.

The structure would be a closure. You would define
some small machinery to create it, access the slots,
etc.

Typical for homegrown structure/object systems
in Scheme.

-- 
http://lispm.dyndns.org
From: Kaz Kylheku
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <1173830391.557952.133400@b75g2000hsg.googlegroups.com>
On Mar 13, 3:40 pm, "Karol Skocik" <············@gmail.com> wrote:
> Hi,
>   is there any way to create something like defstruct, in the fashion
> of flet for example, where when you go out of scope the definition
> disappears?
>
> like:
>
> (letstruct ((struct (slot-1 slot-2 slot-3)))
>                   (+ (struct-slot-1 struct-slot-2 struct-slot-3)))

What happens with any objects of this type that escape from that
scope? What is their type now? ;)
From: Karol Skocik
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <1173830586.352641.159560@e1g2000hsg.googlegroups.com>
On Mar 14, 12:59 am, "Kaz Kylheku" <········@gmail.com> wrote:
> On Mar 13, 3:40 pm, "Karol Skocik" <············@gmail.com> wrote:
>
> > Hi,
> >   is there any way to create something like defstruct, in the fashion
> > of flet for example, where when you go out of scope the definition
> > disappears?
>
> > like:
>
> > (letstruct ((struct (slot-1 slot-2 slot-3)))
> >                   (+ (struct-slot-1 struct-slot-2 struct-slot-3)))
>
> What happens with any objects of this type that escape from that
> scope? What is their type now? ;)

hmm, I forgot about that ;) so my post is basically a late night
brainfart :))
From: Espen Vestre
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <m1zm6guwur.fsf@gazonk.vestre.net>
"Kaz Kylheku" <········@gmail.com> writes:

> What happens with any objects of this type that escape from that
> scope? What is their type now? ;)

The same - but unnamed?
-- 
  (espen)
From: John Thingstad
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <op.to5olqzdpqzri1@pandora.upc.no>
On Wed, 14 Mar 2007 00:40:56 +0100, Karol Skocik <············@gmail.com>  
wrote:

> Hi,
>   is there any way to create something like defstruct, in the fashion
> of flet for example, where when you go out of scope the definition
> disappears?
>
> like:
>
> (letstruct ((struct (slot-1 slot-2 slot-3)))
> 		  (+ (struct-slot-1 struct-slot-2 struct-slot-3)))
>
> Thanks for any ideas...
>   Karol
>


Why do you wnat to do this?
Normally I just use packages to reduce clutter.

Seems to me you can hack this to work by

                         (defparameter *new-package-name* (intern (gensym)  
*package*)
creating a package      (defpackage *new-package-name*)
store old package       (defparameter *old-package* *package*)
Go into the new package (in-package *new-package-name*)
Do you struff           (destruct wierd one two three)
                         (defparameter s (make-wierd :one 1 :two 2 :three  
3))
	                  (wierd-one s)
Go back to old package  (in-package (package-name *old-package*))
delete the new package  (delete-package *new-package-name*)
	                  (unintern *new-package-name*)
                         (makunbound *new-package-name*)
                         (makunbound '*old-package*)
or something like that
-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: John Thingstad
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <op.to5o0dropqzri1@pandora.upc.no>
On Wed, 14 Mar 2007 02:47:40 +0100, John Thingstad  
<··············@chello.no> wrote:

> On Wed, 14 Mar 2007 00:40:56 +0100, Karol Skocik  
> <············@gmail.com> wrote:
>
>> Hi,
>>   is there any way to create something like defstruct, in the fashion
>> of flet for example, where when you go out of scope the definition
>> disappears?
>>
>> like:
>>
>> (letstruct ((struct (slot-1 slot-2 slot-3)))
>> 		  (+ (struct-slot-1 struct-slot-2 struct-slot-3)))
>>
>> Thanks for any ideas...
>>   Karol
>>
>
>
> Why do you wnat to do this?
> Normally I just use packages to reduce clutter.
>
> Seems to me you can hack this to work by
>
>                          (defparameter *new-package-name* (intern  
> (gensym) *package*)
> creating a package      (defpackage *new-package-name*)
> store old package       (defparameter *old-package* *package*)
> Go into the new package (in-package *new-package-name*)
> Do you struff           (destruct wierd one two three)
>                          (defparameter s (make-wierd :one 1 :two 2  
> :three 3))
> 	                  (wierd-one s)
> Go back to old package  (in-package (package-name *old-package*))
> delete the new package  (delete-package *new-package-name*)
> 	                  (unintern *new-package-name*)
>                          (makunbound *new-package-name*)
>                          (makunbound '*old-package*)
> or something like that

Or if only the struct should be in that package use intern and then  
unintern
for struct name and package quilifier.
(defstruct (intern 'name *new-package*) ...)
(#.*new-package*:wierd-one s)
(unintern 'name)
(delete-package *new-package*)

A working implementation is left as a exercise ;)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Karol Skocik
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <1173860919.725684.76340@l77g2000hsb.googlegroups.com>
On Mar 14, 2:56 am, "John Thingstad" <··············@chello.no> wrote:
> On Wed, 14 Mar 2007 02:47:40 +0100, John Thingstad
>
>
>
> <··············@chello.no> wrote:
> > On Wed, 14 Mar 2007 00:40:56 +0100, Karol Skocik
> > <············@gmail.com> wrote:
>
> >> Hi,
> >>   is there any way to create something like defstruct, in the fashion
> >> of flet for example, where when you go out of scope the definition
> >> disappears?
>
> >> like:
>
> >> (letstruct ((struct (slot-1 slot-2 slot-3)))
> >>                  (+ (struct-slot-1 struct-slot-2 struct-slot-3)))
>
> >> Thanks for any ideas...
> >>   Karol
>
> > Why do you wnat to do this?
> > Normally I just use packages to reduce clutter.
>
> > Seems to me you can hack this to work by
>
> >                          (defparameter *new-package-name* (intern
> > (gensym) *package*)
> > creating a package      (defpackage *new-package-name*)
> > store old package       (defparameter *old-package* *package*)
> > Go into the new package (in-package *new-package-name*)
> > Do you struff           (destruct wierd one two three)
> >                          (defparameter s (make-wierd :one 1 :two 2
> > :three 3))
> >                      (wierd-one s)
> > Go back to old package  (in-package (package-name *old-package*))
> > delete the new package  (delete-package *new-package-name*)
> >                      (unintern *new-package-name*)
> >                          (makunbound *new-package-name*)
> >                          (makunbound '*old-package*)
> > or something like that
>
> Or if only the struct should be in that package use intern and then
> unintern
> for struct name and package quilifier.
> (defstruct (intern 'name *new-package*) ...)
> (#.*new-package*:wierd-one s)
> (unintern 'name)
> (delete-package *new-package*)
>
> A working implementation is left as a exercise ;)
>
> --
> Using Opera's revolutionary e-mail client:http://www.opera.com/mail/

this is a nice solution, I will go this way.

thanks!

Karol
From: Peter Seibel
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <87bqivbxc6.fsf@gigamonkeys.com>
"John Thingstad" <··············@chello.no> writes:

> On Wed, 14 Mar 2007 00:40:56 +0100, Karol Skocik
> <············@gmail.com>  wrote:
>
>> Hi,
>>   is there any way to create something like defstruct, in the fashion
>> of flet for example, where when you go out of scope the definition
>> disappears?
>>
>> like:
>>
>> (letstruct ((struct (slot-1 slot-2 slot-3)))
>> 		  (+ (struct-slot-1 struct-slot-2 struct-slot-3)))
>>
>> Thanks for any ideas...
>>   Karol
>>
>
>
> Why do you wnat to do this?
> Normally I just use packages to reduce clutter.
>
> Seems to me you can hack this to work by
>
>                         (defparameter *new-package-name* (intern
> (gensym)  *package*)
> creating a package      (defpackage *new-package-name*)
> store old package       (defparameter *old-package* *package*)
> Go into the new package (in-package *new-package-name*)
> Do you struff           (destruct wierd one two three)
>                         (defparameter s (make-wierd :one 1 :two 2
> :three  3))
> 	                  (wierd-one s)
> Go back to old package  (in-package (package-name *old-package*))
> delete the new package  (delete-package *new-package-name*)
> 	                  (unintern *new-package-name*)
>                         (makunbound *new-package-name*)
>                         (makunbound '*old-package*)
> or something like that

Mmmm, that doesn't reallly work the way you seem to think it does.
DEFPACKAGE and IN-PACKAGE are macros and do not evaluate the package
name form. You could try using MAKE-PACKAGE and SETF'ing *PACKAGE* but
it's not clear what the point would be.

-Peter
From: John Thingstad
Subject: Re: how to create local defstructs?
Date: 
Message-ID: <op.to6wgsp3pqzri1@pandora.upc.no>
On Wed, 14 Mar 2007 17:32:06 +0100, Peter Seibel <·····@gigamonkeys.com>  
wrote:

>> Seems to me you can hack this to work by
>>
>>                         (defparameter *new-package-name* (intern
>> (gensym)  *package*)
>> creating a package      (defpackage *new-package-name*)
>> store old package       (defparameter *old-package* *package*)
>> Go into the new package (in-package *new-package-name*)
>> Do you struff           (destruct wierd one two three)
>>                         (defparameter s (make-wierd :one 1 :two 2
>> :three  3))
>> 	                  (wierd-one s)
>> Go back to old package  (in-package (package-name *old-package*))
>> delete the new package  (delete-package *new-package-name*)
>> 	                  (unintern *new-package-name*)
>>                         (makunbound *new-package-name*)
>>                         (makunbound '*old-package*)
>> or something like that
>
> Mmmm, that doesn't reallly work the way you seem to think it does.
> DEFPACKAGE and IN-PACKAGE are macros and do not evaluate the package
> name form. You could try using MAKE-PACKAGE and SETF'ing *PACKAGE* but
> it's not clear what the point would be.
>
> -Peter

Yes, thought of that this morning (I wrote it a AM..)
By putting it in a separate package structure and generated function can be
handled separately. Thus when you delete the package they disappear.
Not quite sure I see the point either..

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/