unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* get procedure?
@ 2010-02-17 18:25 Paul Emsley
  2010-02-17 18:30 ` Paul Emsley
  2010-02-17 19:03 ` Thomas Thiriez
  0 siblings, 2 replies; 5+ messages in thread
From: Paul Emsley @ 2010-02-17 18:25 UTC (permalink / raw)
  To: guile-user


I don't understand what xxx is.  Can you help? (Bit of a noob question, 
I feel).

   SCM rest = SCM_EOL;
   SCM arg_list = SCM_EOL;
   arg_list = scm_cons(SCM_MAKINUM(4), arg_list);
   arg_list = scm_cons(SCM_MAKINUM(1), arg_list);

   SCM func = xxx("-");

   SCM v = scm_apply_1(func, arg_list, rest);
   // Now v should be a scheme int 3
  

Thanks,

Paul.
  





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: get procedure?
  2010-02-17 18:25 get procedure? Paul Emsley
@ 2010-02-17 18:30 ` Paul Emsley
  2010-02-17 19:03 ` Thomas Thiriez
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Emsley @ 2010-02-17 18:30 UTC (permalink / raw)
  To: guile-user@gnu.org

Paul Emsley wrote:
> I don't understand what xxx is.  Can you help? (Bit of a noob question, 
> I feel).
>
>    SCM rest = SCM_EOL;
>    SCM arg_list = SCM_EOL;
>    arg_list = scm_cons(SCM_MAKINUM(4), arg_list);
>    arg_list = scm_cons(SCM_MAKINUM(1), arg_list);
>
>    SCM func = xxx("-");
>
>    SCM v = scm_apply_1(func, arg_list, rest);
>    // Now v should be a scheme int 3
>   
>   

Just to be clear, I don't mean scm_minus(), this was an attempt at 
simplification  :) I have a scheme function (actually, it's 
record-accessor) passed to a c++ function that I want to apply to the 
argument list (the record and a symbol of course).

Thanks,

Paul.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: get procedure?
  2010-02-17 18:25 get procedure? Paul Emsley
  2010-02-17 18:30 ` Paul Emsley
@ 2010-02-17 19:03 ` Thomas Thiriez
  2010-02-17 19:54   ` dsmich
  2010-02-17 20:07   ` Andy Wingo
  1 sibling, 2 replies; 5+ messages in thread
From: Thomas Thiriez @ 2010-02-17 19:03 UTC (permalink / raw)
  To: Paul Emsley; +Cc: guile-user

Hi Paul,

Here is what you should use for xxx:

SCM FindFunc(const char *funcName)
{
   SCM funcSymbol = scm_c_lookup(funcName);

   if (!funcSymbol)
      // undefined symbol
      return 0;

   return scm_variable_ref(funcSymbol);
}

Regards,
Thomas

On Feb 17, 2010, at 7:25 PM, Paul Emsley wrote:

> 
> I don't understand what xxx is.  Can you help? (Bit of a noob question, I feel).
> 
>  SCM rest = SCM_EOL;
>  SCM arg_list = SCM_EOL;
>  arg_list = scm_cons(SCM_MAKINUM(4), arg_list);
>  arg_list = scm_cons(SCM_MAKINUM(1), arg_list);
> 
>  SCM func = xxx("-");
> 
>  SCM v = scm_apply_1(func, arg_list, rest);
>  // Now v should be a scheme int 3
> 
> Thanks,
> 
> Paul.
> 
> 
> 





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: get procedure?
  2010-02-17 19:03 ` Thomas Thiriez
@ 2010-02-17 19:54   ` dsmich
  2010-02-17 20:07   ` Andy Wingo
  1 sibling, 0 replies; 5+ messages in thread
From: dsmich @ 2010-02-17 19:54 UTC (permalink / raw)
  To: Thomas Thiriez, Paul Emsley; +Cc: guile-user


---- Thomas Thiriez <thomas@twistedwave.com> wrote: 
> Hi Paul,
> 
> Here is what you should use for xxx:
> 
> SCM FindFunc(const char *funcName)
> {
>    SCM funcSymbol = scm_c_lookup(funcName);
> 
>    if (!funcSymbol)
>       // undefined symbol
>       return 0;
> 
>    return scm_variable_ref(funcSymbol);
> }

Oi!

Never ever ever let 0 be turned loose to Guile as a SCM value.  Segfaults will happen!

Also, funcSymbol will never be 0 (or madness would ensue).

-Dale





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: get procedure?
  2010-02-17 19:03 ` Thomas Thiriez
  2010-02-17 19:54   ` dsmich
@ 2010-02-17 20:07   ` Andy Wingo
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Wingo @ 2010-02-17 20:07 UTC (permalink / raw)
  To: Thomas Thiriez; +Cc: guile-user

Hi,

On Wed 17 Feb 2010 20:03, Thomas Thiriez <thomas@twistedwave.com> writes:

> Here is what you should use for xxx:

Hm, not quite :)

> SCM FindFunc(const char *funcName)
> {
>    SCM funcSymbol = scm_c_lookup(funcName);

scm_c_lookup gives you a variable object, as you note below; better to
call it `funcVar' (or `func_var' if you're shift-impaired :)

>    if (!funcSymbol)

If the var is unbound, scm_c_lookup will throw, no need for error
checking. Also perhaps you were looking for scm_is_false (func_var); see
the section entitled "Dynamic Types" in the manual.

>       // undefined symbol
>       return 0;

Likewise don't return 0 as a SCM

>    return scm_variable_ref(funcSymbol);

This part is right :-)

Cheers,

Andy
-- 
http://wingolog.org/




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-02-17 20:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-17 18:25 get procedure? Paul Emsley
2010-02-17 18:30 ` Paul Emsley
2010-02-17 19:03 ` Thomas Thiriez
2010-02-17 19:54   ` dsmich
2010-02-17 20:07   ` 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).