--
You received this message because you are subscribed to the Google Groups "shedskin-discuss" group.
To post to this group, send email to shedskin...@googlegroups.com.
To unsubscribe from this group, send email to shedskin-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/shedskin-discuss?hl=en.
Great, I'll have a look at it.
But it'd be very nice to have generalized support for this in the
future ; maybe I'll look for a clean solution -- if you've not planned
to do it yourself, of course.
> -mixing of None and 0 is more worrisome. I'm afraid this cannot be supportedYes, for now this is the only case where I had the problem, so this is
> at all, nor at any time in the near future. is this only a problem for
> islice? could we perhaps add a warning here, saying that 0 is used instead
> of None, for integers?
not critical (a workaround is possible in Python), and a warning would
suffice.
I wonder if it would be possible to use __null for None, which is a
typed wrapper for a null integer, but faking the C++ type-checker
(I've to check GCC's template issues).
There are alternatives to stdarg with some type safety: C++0x variadic
templates or boost::mpl pseudo-variadic templates. I don't know if
this is desirable, though.
You may use both of them for islice's 'stop' argument
-starmap. I don't think we can easily support this one for now.. I would be quite satisfied if everything else can be supported though.
> is just modeled as the type of the first element of what it would be inAFAIR, that's fine for itertools: it works on sequences of only one type.
> python.. which should be enough to do type inference on itertools.
Looks good, I'll play with this soon.
Maybe in some cases like this one, it'd be cool to the have C++ code
generated by Shed Skin when needed, instead of pure C++ templates.
And yes, it looks like the return value of izip_longest will be
problematic... :s
Please, don't spend too much time on Shed Skin if you have an exam on Sunday ;-)
Everything looks fine if all 'func' s parameters are of the same type
; otherwise it's not the case at all :s
template <typename T> iter<T> imap(T (*func)(int, ...), int argc, ...)
The line I commented ("oops"), is another (bigger) problem: how can we
call the variadic function 'func', without knowing in advance the
number of parameters?
Actually, I think there might be less effort to code small code
generators than to try to overcome C++ limitations...
Then template specialization should be enough to support both None and
0, great :-)
Would it be a problem to do this additional cast everywhere ?
I managed to get a working itertools.izip implementation (you've
really done awesome improvements :p), but I needed some changes to the
current unpacking handler.
It also fixes a bug (when nrvarargs is 0, the first comma is not
added, but 0 still is).
That's the first thing I wanted to do (I agree it looks better, and it
doesn't require changes in shedskin), but unfortunately, va_args
requires the number of variadic arguments to be put on the stack just
after the variadic arguments themselves, so the compiler complains
with this version.
> btw, we will lose type checking of course with variadics. also, we probably
> want to optimize for sequence types (pyseq, as done in places in
> lib/builtin.?pp), because iterating over them can be done much faster than
> using the normal iterator protocol. so I'm thinking along the lines of
> adding some kind of attribute to be able to identify types at runtime.. what
> would be your thoughts on this?
Yes, there is room for optimization there.
But, actually, isn't it possible to do the distinction at compile time ?
Removing the virtual calls would allow to inline the iterator
protocol, and templates templates could be used to replace the dynamic
polymorphism (in case we don't mind allowing a function to accept
parameters with different sequence types at runtime).
If it isn't possible for some reason, then yes, I second your idea.
2009/12/17 Mark Dufour <mark....@gmail.com>:
>> It also fixes a bug (when nrvarargs is 0, the first comma is not
>> added, but 0 still is).
> thanks for the patch! but could you please also give me an example for which
> the bug occurs..? I would think, if the are no varargs, then there are no
> following args, so we don't need a comma after '0'..? in any case, I cannot
> reproduce the problem..
You're right, I though about it yesterday evening. In fact I should
have written :
> It also *adds* a bug
Sorry for this one ;-)
But, while this doesn't solve a problem that didn't exist, it's not
really a bug, it just changes the behaviour of shedskin by generating
calls like f() instead of f(0) when no parameter is supplied to a
function.
Playing a bit with this, I found that it may be desirable, because it
allows me to handle the "no parameter" case of izip: having three cpp
funtions :
inline izipiter<void*> *izip() {
return new izipiter<void*>();
}
template<class T> inline izipiter<T> *izip(pyiter<T> *iterable) {
return new izipiter<T>(iterable);
}
template<class T> inline izipiter<T> *izip(pyiter<T> *iterable, int
iterable_count, ...) {
// ...
}
We can handle any number of parameters, including 0.
Which actually would have been possible without the change by testing
if "iterable" is 0, but I personally prefer with the change because
the compiler would complain if the "no parameter" function was not
implemented, while it would say nothing if the "0" case was not
properly handled.
Best regards,
--
Jérémie
That's the first thing I wanted to do (I agree it looks better, and it
doesn't require changes in shedskin), but unfortunately, va_args
requires the number of variadic arguments to be put on the stack just
after the variadic arguments themselves, so the compiler complains
with this version.
Best regards,
--
Jérémie
--
You received this message because you are subscribed to the Google Groups "shedskin-discuss" group.
To post to this group, send email to shedskin...@googlegroups.com.
To unsubscribe from this group, send email to shedskin-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/shedskin-discuss?hl=en.
Did you mean
va_start(ap, n);
instead of
va_start(ap, a);
?
Doing "va_start(ap, n);", gives me the following warning:
itertools.hpp:659: warning: second parameter of ‘va_start’ not last
named argument
And the C++98 standard says (18.7.23.3):
> The restrictions that ISO C places on the second parameter to the va_start() macro in header
> <stdarg.h> are different in this International Standard. The parameter parmN is the identifier of the
> rightmost parameter in the variable parameter list of the function definition (the one just before the ...).
So, unless I missed something, we have to pass the number of variadic
arguments just before them, ie. after the "non-variadic" first
iterable.
> I will reply to the rest of your mail tomorrow. btw, note that this works
> since a few hours:
>
> print sorted([[2,3,4], [5,6], [7]], key=len)
> print map(len, ['a','bc'])
> print map(str, range(12))
> print map(list, 'abc')
\o/
Best regards,
--
Jérémie
Did you mean
va_start(ap, n);
instead of
va_start(ap, a);
?
Oh! My mistake...
For some reason I though the second parameter to va_start had to be
the number of variadic parameters...
This is what appends when I don't read the man ;-)
So, the first version should work, and I learned something new, thanks ;-)
--
Jérémie
But, actually, isn't it possible to do the distinction at compile time ?
Removing the virtual calls would allow to inline the iterator
protocol, and templates templates could be used to replace the dynamic
polymorphism (in case we don't mind allowing a function to accept
parameters with different sequence types at runtime).
If it isn't possible for some reason, then yes, I second your idea.