* Does anyone have an applicable struct example
@ 2010-06-25 9:14 Tristan Colgate
2010-06-28 10:06 ` Tristan Colgate
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Tristan Colgate @ 2010-06-25 9:14 UTC (permalink / raw)
To: guile-user
Hi all,
I'd like to make use of the applicable structs feature but am
running into problems.
From what I can gather from the release note that mentions it, the
following should work,
instead, I get a segfault.
scheme@(guile-user)> (define <mything-vtable> (make-struct
<applicable-struct-vtable> 0))
scheme@(guile-user)> (define mything (make-struct <mything-vtable> 0
(lambda()(display "some code")(newline))))
Segmentation fault (core dumped)
Looking around goops.scm I can see some classes for applicable structs
that look a bit nicer, but these seem
to use set-object-procedure! which isn't exported (and I can't find a
definition)....
scheme@(guile-user)> (use-modules (oop goops))
scheme@(guile-user)> (define-class <myclass> (<applicable-struct>))
scheme@(guile-user)> (make <myclass> #:procedure (lambda()(display
"some code")(nelwine)))
<stdin>:5:58: warning: possibly unbound variable `nelwine'
Throw to key `unbound-variable':
ERROR: In procedure module-lookup:
ERROR: Unbound variable: set-object-procedure!
I tried using a generic instead but it didn't make much difference.
What am I doing wrong?
--
Tristan Colgate-McFarlane
----
"You can get all your daily vitamins from 52 pints of guiness, and a
glass of milk"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Does anyone have an applicable struct example
2010-06-25 9:14 Does anyone have an applicable struct example Tristan Colgate
@ 2010-06-28 10:06 ` Tristan Colgate
2010-06-29 2:16 ` Nala Ginrut
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Tristan Colgate @ 2010-06-28 10:06 UTC (permalink / raw)
To: guile-user
I've had a further play and read around the source, and got things
working via goops atleast (still not sure how to use the applicable
structs directly).
The following code works....
(define-class <myclass> (<applicable-struct>) (a))
(make <myclass>)
(slot-set! $1 'procedure (lambda()(...)))
($1)
(slot-set! $1 'a 1)
etc...
This plays nice with write and display method overrides too (which is
what I was after).
On 25 June 2010 10:14, Tristan Colgate <tcolgate@gmail.com> wrote:
> Hi all,
>
> I'd like to make use of the applicable structs feature but am
> running into problems.
>
> From what I can gather from the release note that mentions it, the
> following should work,
> instead, I get a segfault.
>
> scheme@(guile-user)> (define <mything-vtable> (make-struct
> <applicable-struct-vtable> 0))
> scheme@(guile-user)> (define mything (make-struct <mything-vtable> 0
> (lambda()(display "some code")(newline))))
> Segmentation fault (core dumped)
>
> Looking around goops.scm I can see some classes for applicable structs
> that look a bit nicer, but these seem
> to use set-object-procedure! which isn't exported (and I can't find a
> definition)....
>
> scheme@(guile-user)> (use-modules (oop goops))
> scheme@(guile-user)> (define-class <myclass> (<applicable-struct>))
> scheme@(guile-user)> (make <myclass> #:procedure (lambda()(display
> "some code")(nelwine)))
> <stdin>:5:58: warning: possibly unbound variable `nelwine'
> Throw to key `unbound-variable':
> ERROR: In procedure module-lookup:
> ERROR: Unbound variable: set-object-procedure!
>
> I tried using a generic instead but it didn't make much difference.
>
> What am I doing wrong?
>
> --
> Tristan Colgate-McFarlane
> ----
> "You can get all your daily vitamins from 52 pints of guiness, and a
> glass of milk"
>
--
Tristan Colgate-McFarlane
----
"You can get all your daily vitamins from 52 pints of guiness, and a
glass of milk"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Does anyone have an applicable struct example
2010-06-25 9:14 Does anyone have an applicable struct example Tristan Colgate
2010-06-28 10:06 ` Tristan Colgate
@ 2010-06-29 2:16 ` Nala Ginrut
2010-06-29 9:56 ` Andy Wingo
2010-08-29 18:48 ` Andy Wingo
3 siblings, 0 replies; 5+ messages in thread
From: Nala Ginrut @ 2010-06-29 2:16 UTC (permalink / raw)
To: Tristan Colgate; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 577 bytes --]
2010/6/25 Tristan Colgate <tcolgate@gmail.com>
> scheme@(guile-user)> (use-modules (oop goops))
> scheme@(guile-user)> (define-class <myclass> (<applicable-struct>))
> scheme@(guile-user)> (make <myclass> #:procedure (lambda()(display
> "some code")(nelwine)))
> <stdin>:5:58: warning: possibly unbound variable `nelwine'
> Throw to key `unbound-variable':
> ERROR: In procedure module-lookup:
> ERROR: Unbound variable: set-object-procedure!
>
> I tried using a generic instead but it didn't make much difference.
>
> What am I doing wrong?
>
>
NOT "nelwine" IT IS "newline"
[-- Attachment #2: Type: text/html, Size: 959 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Does anyone have an applicable struct example
2010-06-25 9:14 Does anyone have an applicable struct example Tristan Colgate
2010-06-28 10:06 ` Tristan Colgate
2010-06-29 2:16 ` Nala Ginrut
@ 2010-06-29 9:56 ` Andy Wingo
2010-08-29 18:48 ` Andy Wingo
3 siblings, 0 replies; 5+ messages in thread
From: Andy Wingo @ 2010-06-29 9:56 UTC (permalink / raw)
To: Tristan Colgate; +Cc: guile-user
Hi Tristan,
On Fri 25 Jun 2010 11:14, Tristan Colgate <tcolgate@gmail.com> writes:
> I'd like to make use of the applicable structs feature but am
> running into problems.
Apologies for the lack of docs; it's on my list, but I haven't gotten to
it yet.
> From what I can gather from the release note that mentions it, the
> following should work,
> instead, I get a segfault.
>
> scheme@(guile-user)> (define <mything-vtable> (make-struct
> <applicable-struct-vtable> 0))
> scheme@(guile-user)> (define mything (make-struct <mything-vtable> 0
> (lambda()(display "some code")(newline))))
> Segmentation fault (core dumped)
Ew, will fix.
> Looking around goops.scm I can see some classes for applicable structs
> that look a bit nicer, but these seem
> to use set-object-procedure! which isn't exported (and I can't find a
> definition)....
I have applied your fix to this one.
> What am I doing wrong?
You are doing everything right, it's just that you found a couple bugs
in a recently-rewritten part of Guile. Apologies again!
Happy hacking,
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Does anyone have an applicable struct example
2010-06-25 9:14 Does anyone have an applicable struct example Tristan Colgate
` (2 preceding siblings ...)
2010-06-29 9:56 ` Andy Wingo
@ 2010-08-29 18:48 ` Andy Wingo
3 siblings, 0 replies; 5+ messages in thread
From: Andy Wingo @ 2010-08-29 18:48 UTC (permalink / raw)
To: Tristan Colgate; +Cc: guile-user
Hi Tristan,
On Fri 25 Jun 2010 02:14, Tristan Colgate <tcolgate@gmail.com> writes:
> scheme@(guile-user)> (define <mything-vtable> (make-struct
> <applicable-struct-vtable> 0))
> scheme@(guile-user)> (define mything (make-struct <mything-vtable> 0
> (lambda()(display "some code")(newline))))
> Segmentation fault (core dumped)
Thanks for the report. I have fixed Guile so that it now does this:
scheme@(guile-user)> (define <mything-vtable> (make-struct <applicable-struct-vtable> 0))
scheme@(guile-user)> (make-struct <mything-vtable> 0)
<unnamed port>:2:1: In procedure struct-vtable?:
<unnamed port>:2:1: vtable has invalid layout: #f
Indeed you didn't specify a layout when making <mything-vtable>. Try
this:
scheme@(guile-user)> (define <mything-vtable> (make-struct <applicable-struct-vtable> 0 'pw))
scheme@(guile-user)> (make-struct <mything-vtable> 0)
$1 = #<struct:23ce1e0 pw 24a8ec0>
scheme@(guile-user)> (make-struct <mything-vtable> 0 (lambda () 10))
$2 = #<struct:23ce1e0 pw 24b7920 proc: #<procedure 24b7940 at <current input>:4:32 ()>>
scheme@(guile-user)> ($2)
$3 = 10
You see, 'pw is the "minimum layout" for an applicable struct:
scheme@(guile-user)> (define <mything-vtable> (make-struct <applicable-struct-vtable> 0 'pr))
<unnamed port>:1:26: In procedure %inherit-vtable-magic:
<unnamed port>:1:26: invalid applicable struct layout
To add fields you add them after the 'pw. Like 'pwpwpw, for two user
fields.
This whole thing is very low-level though, and needs proper
documentation. It would be nice to clean up the "layout" to not be a
symbol, but that's a job...
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-08-29 18:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-25 9:14 Does anyone have an applicable struct example Tristan Colgate
2010-06-28 10:06 ` Tristan Colgate
2010-06-29 2:16 ` Nala Ginrut
2010-06-29 9:56 ` Andy Wingo
2010-08-29 18:48 ` Andy Wingo
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).