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
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)))))
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
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? ;)
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 :))
"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)
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/
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/
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
"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
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/