guile-user
[Top][All Lists]
Advanced

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

Re: passing flags to a function


From: Dan McMahill
Subject: Re: passing flags to a function
Date: Tue, 02 May 2006 12:21:10 -0400
User-agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.7.6) Gecko/20050412

Ludovic Courtès wrote:
Hi,

Dan McMahill <address@hidden> writes:


I can do something like

SCM scm_myfn(SCM flags)
{

 myfn (scm_num2int (flags, SCM_ARG1, "myfn"));

 return SCM_BOOLEAN_T;

}

but I'm not sure of the best way to define the flags in scheme.  Or
maybe this is not "the scheme way".


What you describe above is doable and is an approach sometimes taken.
See for instance the POSIX functions in Guile, e.g., `popen'.

Personally, I prefer to pass a list of symbols rather than a single
number in such situations.  This might require some more work if you
need to convert those flags to a C or'ed integer, but not so much
because (i) symbols can be compared with `eq' which is fast, (ii)
the list of flags may usually be small, and (iii) the number of values
that can be taken by the flags is small as well.



Hi Ludovic,

Thanks for the reply. Could you show a short example of what the scheme function call might look like?

Are you meaning

(foo (list 'flag1 'flag2 'someotherflag))

I don't care much about speed in this particular case.

Thanks
-Dan




reply via email to

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