From: ludovic.courtes@laas.fr (Ludovic Courtès)
Cc: guile-user@gnu.org
Subject: Re: passing flags to a function
Date: Tue, 02 May 2006 17:34:05 +0200 [thread overview]
Message-ID: <874q08qw42.fsf@laas.fr> (raw)
In-Reply-To: <44574FA0.1050108@mtl.mit.edu> (Dan McMahill's message of "Tue, 02 May 2006 08:25:04 -0400")
Hi,
Dan McMahill <mcmahill@mtl.mit.edu> 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.
SCM_DEFINE (scm_func, "func", 0, 0, 1,
(SCM flags),
"My function takes any number of symbols.")
#define FUNC_NAME "func"
{
int c_flags;
for (c_flags = 0;
scm_is_pair (flags);
flags = SCM_CDR (flags))
{
SCM f = SCM_CAR (flags);
if (scm_is_eq (f, my_first_flag_sym))
c_flags |= MY_FIRST_FLAG;
else if (scm_is_eq (f, my_second_flag_sym))
c_flags |= MY_SECOND_FLAG;
else
scm_wrong_type_arg (FUNC_NAME, 1, f);
}
/* ... */
}
#undef FUNC_NAME
But this is debatable and it also depends on the context.
Thanks,
Ludovic.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
next prev parent reply other threads:[~2006-05-02 15:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-02 12:25 passing flags to a function Dan McMahill
2006-05-02 15:34 ` Ludovic Courtès [this message]
2006-05-02 16:21 ` Dan McMahill
2006-05-02 16:55 ` Ludovic Courtès
2006-05-02 16:56 ` Dan McMahill
2006-05-07 21:03 ` Marius Vollmer
2006-05-02 16:14 ` Clinton Ebadi
2006-05-03 1:43 ` Kevin Ryde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874q08qw42.fsf@laas.fr \
--to=ludovic.courtes@laas.fr \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).