guile-user
[Top][All Lists]
Advanced

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

Re: Does anyone have an applicable struct example


From: Andy Wingo
Subject: Re: Does anyone have an applicable struct example
Date: Sun, 29 Aug 2010 11:48:33 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hi Tristan,

On Fri 25 Jun 2010 02:14, Tristan Colgate <address@hidden> 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/



reply via email to

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