* Re: Trouble with returning parameters passed in to C primitives.
@ 2012-12-07 9:14 Richard Shann
0 siblings, 0 replies; 3+ messages in thread
From: Richard Shann @ 2012-12-07 9:14 UTC (permalink / raw)
To: guile-user
Thank you! I am much clearer on the meaning of quote now.
Richard Shann
> On Dec 7, 2012 5:51 AM, "Richard Shann" <address@hidden> wrote:
> > If I pass 'a in as a parameter I get something back which prints on
> the
> > console as (quote a) but which is not eq? to 'a
>
> You seem to be double quoting the value. No need for ' the second
> time.
>
> > I can pass in a string and get an equal? string back. But what I
> really
> > want to do is pass in a procedure and execute it if I get it back,
> thus
> >
> > (set! choice (d-PopupMenu (list '("Offset Position" . do-offset))))
>
> Here you pass the symbol "do-offset" rather than the value. read up
> on quote and quasiquote syntax. Use unquote to insert the /value/ of
> do-offset:
>
> (set! choice (d-PopupMenu (list `("Offset Position" . ,do-offset))))
>
> or:
>
> (set! choice (d-PopupMenu (list (cons "Offset Position" do-offset))))
>
> > (#f Wrong type to apply: ~S (do-offset) #f)
> >
>
> You are trying to apply a list contain a symbol, when it should just
> be a procedure: no list or symbol.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Trouble with returning parameters passed in to C primitives.
@ 2012-12-06 11:20 Richard Shann
2012-12-07 1:59 ` Daniel Hartwig
0 siblings, 1 reply; 3+ messages in thread
From: Richard Shann @ 2012-12-06 11:20 UTC (permalink / raw)
To: guile-user
In GNU/Denemo we have been calling functions written in C from scheme by
defining procedures via scm_c_define_gsubr. Recently I have tried
returning one of the parameters passed (more exactly, the scm_list_ref
of a scm_car() of one of the parameters) and I have run into trouble.
If I pass 'a in as a parameter I get something back which prints on the
console as (quote a) but which is not eq? to 'a
I can pass in a string and get an equal? string back. But what I really
want to do is pass in a procedure and execute it if I get it back, thus
(set! choice (d-PopupMenu (list '("Offset Position" . do-offset))))
(if choice
(choice))
where do-offset is defined as (define (do-offset) (display "hello world"))
and d-PopupMenu is my C-primitive which gets a choice from the user.
If the user cancels choice is #f and all is well, if he accepts the one
option on the menu, do-offset is returned but I get the error message
(#f Wrong type to apply: ~S (do-offset) #f)
(BTW I can't find a blow by blow explanation of this error message
anywhere, I see some discussion of earlier versions of it on the net...)
Anyone able to help?
Richard Shann
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Trouble with returning parameters passed in to C primitives.
2012-12-06 11:20 Richard Shann
@ 2012-12-07 1:59 ` Daniel Hartwig
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Hartwig @ 2012-12-07 1:59 UTC (permalink / raw)
To: Richard Shann; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 944 bytes --]
On Dec 7, 2012 5:51 AM, "Richard Shann" <richard.shann@virgin.net> wrote:
> If I pass 'a in as a parameter I get something back which prints on the
> console as (quote a) but which is not eq? to 'a
You seem to be double quoting the value. No need for ' the second time.
> I can pass in a string and get an equal? string back. But what I really
> want to do is pass in a procedure and execute it if I get it back, thus
>
> (set! choice (d-PopupMenu (list '("Offset Position" . do-offset))))
Here you pass the symbol "do-offset" rather than the value. read up on
quote and quasiquote syntax. Use unquote to insert the /value/ of
do-offset:
(set! choice (d-PopupMenu (list `("Offset Position" . ,do-offset))))
or:
(set! choice (d-PopupMenu (list (cons "Offset Position" do-offset))))
> (#f Wrong type to apply: ~S (do-offset) #f)
>
You are trying to apply a list contain a symbol, when it should just be a
procedure: no list or symbol.
[-- Attachment #2: Type: text/html, Size: 1197 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-12-07 9:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-07 9:14 Trouble with returning parameters passed in to C primitives Richard Shann
-- strict thread matches above, loose matches on Subject: below --
2012-12-06 11:20 Richard Shann
2012-12-07 1:59 ` Daniel Hartwig
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).