* Trouble creating SRFI-9 Record in C
@ 2021-09-11 2:27 paul
2021-09-11 3:59 ` Olivier Dion via General Guile related discussions
2021-09-11 13:30 ` Matt Wette
0 siblings, 2 replies; 4+ messages in thread
From: paul @ 2021-09-11 2:27 UTC (permalink / raw)
To: guile-user
Good day guile-users,
I am having a struggle with SRFI-9 records. They look very
convenient, so i'd like to use them in my Guile scripts. However,
i'm not sure how to correctly construct them from C-land. I have
something like the following:
```
(define-record-type <foo>
(make-foo a b)
foo?
(a foo-a)
(b foo-b))
```
In Guile land, that works great. Now, i want to create a foo in C
and pass it to a function in the Guile script. I do something
like the following:
```
scm_c_primitive_load("foo.scm");
scm_call_5(scm_variable_ref(scm_c_lookup("make-foo")),
scm_from_utf8_string("blah"),
scm_from_int32(Int32(42)))
```
However, this results in an error:
guile: uncaught exception:
Wrong type to apply: #<syntax-transformer make-foo>
I've tried with and without (define-module foo) at the top of the
file, that doesn't seem to make a difference. I've been able to
work around the issue by defining a wrapper (define (foo-prime a
b) (make-foo a b)) and using that in C as shown above, but that
feels ugly. I'm probably missing something obvious, but trawling
the mailing list didn't turn up anything i could understand.
Does anyone see what i'm doing wrong, or can i simply not use
SRFI-9 records in this way?
Thanks, 🙌
p.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Trouble creating SRFI-9 Record in C
2021-09-11 2:27 Trouble creating SRFI-9 Record in C paul
@ 2021-09-11 3:59 ` Olivier Dion via General Guile related discussions
2021-09-11 13:30 ` Matt Wette
1 sibling, 0 replies; 4+ messages in thread
From: Olivier Dion via General Guile related discussions @ 2021-09-11 3:59 UTC (permalink / raw)
To: paul, guile-user
On Sat, 11 Sep 2021, paul <paul@inktvis.org> wrote:
> In Guile land, that works great. Now, i want to create a foo in C
> and pass it to a function in the Guile script. I do something
> like the following:
>
> ```
> scm_c_primitive_load("foo.scm");
> scm_call_5(scm_variable_ref(scm_c_lookup("make-foo")),
> scm_from_utf8_string("blah"),
> scm_from_int32(Int32(42)))
> ```
>
> However, this results in an error:
>
> guile: uncaught exception:
> Wrong type to apply: #<syntax-transformer make-foo>
Seems like `make-foo` is a syntax-transformer and not a procedure. You
can not call a syntax-transformer. I don't think you can do much with a
syntax-transformer in C.
>
> I've tried with and without (define-module foo) at the top of the
> file, that doesn't seem to make a difference. I've been able to
> work around the issue by defining a wrapper (define (foo-prime a
> b) (make-foo a b)) and using that in C as shown above, but that
> feels ugly. I'm probably missing something obvious, but trawling
> the mailing list didn't turn up anything i could understand.
By making a wrapper, you're effectively creating a procedure that can
use the `make-foo` syntax because it's in Scheme and it's solved a
expansion time.
--
Olivier Dion
Polymtl
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Trouble creating SRFI-9 Record in C
2021-09-11 2:27 Trouble creating SRFI-9 Record in C paul
2021-09-11 3:59 ` Olivier Dion via General Guile related discussions
@ 2021-09-11 13:30 ` Matt Wette
2021-09-11 23:42 ` paul
1 sibling, 1 reply; 4+ messages in thread
From: Matt Wette @ 2021-09-11 13:30 UTC (permalink / raw)
To: guile-user
maybe add
(define (make-foo-x a b) (make-foo a b))
then call make-foo-x (or reverse names)
On 9/10/21 7:27 PM, paul wrote:
> Good day guile-users,
>
> I am having a struggle with SRFI-9 records. They look very
> convenient, so i'd like to use them in my Guile scripts. However, i'm
> not sure how to correctly construct them from C-land. I have
> something like the following:
>
> ```
> (define-record-type <foo>
> (make-foo a b)
> foo?
> (a foo-a)
> (b foo-b))
> ```
>
> In Guile land, that works great. Now, i want to create a foo in C and
> pass it to a function in the Guile script. I do something like the
> following:
>
> ```
> scm_c_primitive_load("foo.scm");
> scm_call_5(scm_variable_ref(scm_c_lookup("make-foo")),
> scm_from_utf8_string("blah"),
> scm_from_int32(Int32(42)))
> ```
>
> However, this results in an error:
>
> guile: uncaught exception:
> Wrong type to apply: #<syntax-transformer make-foo>
>
> I've tried with and without (define-module foo) at the top of the
> file, that doesn't seem to make a difference. I've been able to work
> around the issue by defining a wrapper (define (foo-prime a b)
> (make-foo a b)) and using that in C as shown above, but that feels
> ugly. I'm probably missing something obvious, but trawling the
> mailing list didn't turn up anything i could understand.
>
> Does anyone see what i'm doing wrong, or can i simply not use SRFI-9
> records in this way?
>
> Thanks, 🙌
> p.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Trouble creating SRFI-9 Record in C
2021-09-11 13:30 ` Matt Wette
@ 2021-09-11 23:42 ` paul
0 siblings, 0 replies; 4+ messages in thread
From: paul @ 2021-09-11 23:42 UTC (permalink / raw)
To: Matt Wette; +Cc: guile-user
Hey Matt,
Yeah that was exactly my workaround 🙂 I was wondering whether i could use the syntax transformer more "directly" from C, or something like that.
Thanks,
paul
> On 11 Sep 2021, at 23:31, Matt Wette <matt.wette@gmail.com> wrote:
>
> maybe add
>
> (define (make-foo-x a b) (make-foo a b))
>
> then call make-foo-x (or reverse names)
>
>> On 9/10/21 7:27 PM, paul wrote:
>> Good day guile-users,
>>
>> I am having a struggle with SRFI-9 records. They look very convenient, so i'd like to use them in my Guile scripts. However, i'm not sure how to correctly construct them from C-land. I have something like the following:
>>
>> ```
>> (define-record-type <foo>
>> (make-foo a b)
>> foo?
>> (a foo-a)
>> (b foo-b))
>> ```
>>
>> In Guile land, that works great. Now, i want to create a foo in C and pass it to a function in the Guile script. I do something like the following:
>>
>> ```
>> scm_c_primitive_load("foo.scm");
>> scm_call_5(scm_variable_ref(scm_c_lookup("make-foo")),
>> scm_from_utf8_string("blah"),
>> scm_from_int32(Int32(42)))
>> ```
>>
>> However, this results in an error:
>>
>> guile: uncaught exception:
>> Wrong type to apply: #<syntax-transformer make-foo>
>>
>> I've tried with and without (define-module foo) at the top of the file, that doesn't seem to make a difference. I've been able to work around the issue by defining a wrapper (define (foo-prime a b) (make-foo a b)) and using that in C as shown above, but that feels ugly. I'm probably missing something obvious, but trawling the mailing list didn't turn up anything i could understand.
>>
>> Does anyone see what i'm doing wrong, or can i simply not use SRFI-9 records in this way?
>>
>> Thanks, 🙌
>> p.
>>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-11 23:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-11 2:27 Trouble creating SRFI-9 Record in C paul
2021-09-11 3:59 ` Olivier Dion via General Guile related discussions
2021-09-11 13:30 ` Matt Wette
2021-09-11 23:42 ` paul
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).