Hi,
Sam Steingold wrote:
--8<---------------cut here---------------start------------->8---
factor(x,{lim}): factorization of x. lim is optional and can be set whenever x is of (possibly recursive) rational type. If lim is set return partial factorization, using primes < lim.
--8<---------------cut here---------------end--------------->8---
>-- do we really need *two* def-call-out forms?)
[Please provide a link to the PARI/GP doc of that function, because variadic stuff in C
is always hairy.]
Short: Yes. The FFI is an automata that (de)serializes values based on an interface
description that it parses. There's no provision (yet) for optional parameters.
That would be too much ad hoc, as the following examples show.
I'd provide the long form only, use &optional at the level of a Lisp wrapper function,
and always supply the optional parameter, possibly as a dummy that the callee C function
can ignore. Basically, *ignoring* extra parameters on the stack is what variadic
functions do, with their decision based on analyzing the first (and required) parameters.
E.g.
- The printf family walks the stack according to a string like "%s%lld%c".
Kaboom if the format string doesn't match the actual parameters (and their sizes).
That's why modern C compilers insist on checking that string.
- open(pathname, flags[, mode]) works like this:
"This [mode] argument must be supplied when
O_CREAT or O_TMPFILE is specified in flags; if neither
O_CREAT nor O_TMPFILE is specified, then mode is ignored."
This works, because in the C calling convention, the callee has no idea how many arguments
were supplied but it sees the first arguments on the top of stack (unlike Pascal).
IOW, call open() with 0 (or ~0) as 3rd argument when not supplied and everything
shall be fine, because it ought to have been supplied whenever it is necessary.
Your snippet from factor() is not enough for me to understand when lim is optional.
It somehow must depend on properties of x. But it can never be optional in the sense
of Prolog, Erlang, Ada or C++, with 2 distinct interfaces. In C, a unique function
exists under a given name and must have means to know whether to expect and
retrieve 2 or 3 arguments from the stack.
"It can be set" is no good. "It *must* be set when ..." is needed with C.
Regards,
Jörg
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.