« first day (239 days earlier)      last day (4701 days later) » 

Xeo
9:00 PM
Ugh. I'm so into templates, I just wanted to templatize my main function... I'm not yet sure on what, though.
3
 
I templated mine on renderer, once
later I decided it was smarter to just use run-time inheritance
is prefix operator++() or operator++(int)?
 
@DeadMG Prefix is without the int.
 
@Xeo You don't know what agrc and argv will be at compile time :)
 
Xeo
@StackedCrooked I do: strings.
 
@Xeo I'm pretty sure argc is not a string.
 
sbi
9:04 PM
@DeadMG Postfix is the odd case, since most unary operators are prefix. You need the odd syntax for the odd case.
 
Xeo
Though C++ should just introduce a new signature for main:
int main(std::vector<std::string>> const& args);
 
@Xeo yeah, but yeah
 
Xeo
optional of course, so it doesn't break code from 20 years ago...
 
should probably a const ref then
 
Xeo
@FredOverflow Nitpicking
 
sbi
9:06 PM
@Xeo Why wouldn't that be a const parameter?
 
@Xeo Why a reference? And why two closing angle brackets?
 
especially with move semantics
 
Xeo
Nevermind this.
 
@Xeo Not unbalanced ones.
 
sbi
@Xeo Only to pair two opening ones, though.
 
Xeo
9:07 PM
And nevermind the second closing >. Like I said, I'm way into templates. Nesting < 2? Sure, keep dreaming.
 
@Xeo main with vector signature requires implicit include of the vector header then?
 
And <string> as well.
 
Xeo
No, they'd become built-in types, obviously. What a question!
 
void awesome_main(std::vector<std::string> args)
{
}

int main(int argc, char** argv)
{
    awesome_main(std::vector<std::string>(argv, argv + argc));
}
 
@Xeo silly me!
@FredOverflow you don't need to rename main for overloading :)
 
9:12 PM
Is it legal to overload main?
 
Xeo
no
 
And awesome_main is so much more awesome.
 
awesomain
 
Xeo
Just GCC bitching or is something wrong here?
 
9:13 PM
and, more importantly, you can use awesome_main on any platform
including Windows, which wants a WinMain entry point
 
Xeo
Just name it the_main
 
> sorry, unimplemented
LOL
 
ok
I figure that, if N > W/2, then it's impossible for there not to be a 2-cardinality set that sums to W
 
GCC is quite polite regarding missing features. I think it's trying to make up for the Internal Compiler Errors.
 
Xeo
@DeadMG Math.SE
 
9:16 PM
been there
 
10
Q: GCC error with variadic templates: "Sorry, unimplemented: cannot expand 'Identifier...' into a fixed-length arugment list"

DennisWhile doing variadic template programming in C++0x on GCC, once in a while I get an error that says "Sorry, unimplemented: cannot expand 'Identifier...' into a fixed-length arugment list." If I remove the "..." in the code then I get a different error: "error: parameter packs not expanded with...

 
Apart from the most basic examples, variadic templates still baffle me.
All those dot dot dots...
 
Well, the way I see it, template argument deduction + overloading works a lot like pattern matching. So I tend to use variadic templates the way I do recursion on e.g. lists.
 
Xeo
@FredOverflow Better yet, doubly dot-dot-dotted!
 
@LucDanton Yes, variadic templates are like pattern matching -- with an ugly syntax :)
 
9:25 PM
There's no denying it
 
Xeo
Partial specialization is pattern matching.
 
(Is there any C++ syntax that isn't ugly?)
 
Xeo
int i = 0; // ?
 
I'd prefer int i := 0 :)
 
Xeo
HERESY!
 
9:27 PM
@FredOverflow +1 for assignment != equals sign.
 
Xeo
@MartinhoFernandes :=!==
Also, I write math like that. Actually, people wrote math like that for hundreds if not thousands of years. I want it to be like that, no some weird colon
 
@Xeo What you write math like this? x == y?
 
Okay, but if math is your role model, then you should ban assignment.
@MartinhoFernandes No he meant x = 0.
 
Xeo
@FredOverflow True enough
 
@FredOverflow But in math that's not assignment. That's equality. It can be true or false.
 
Xeo
9:30 PM
Though, in math, equality and assignment happen at the same time sometimes
 
and of course, x = x + 1 could never be true in math.
 
In math variables are constants.
 
I'd prefer to think of it as snapshots
like the result of querying a database
 
@MartinhoFernandes You can bind variables to values in math, but you cannot re-bind them. = means both "initialization" and "comparison" in maths: "Let x = 0 ... bla bla bla ... if x = 0 then ... bla bla bla".
 
You can claim that's just short for "let x=0 be true" :)
 
9:32 PM
If C++ did not treat assignment as an expression, and if comparisons could not be expression statements, then we would not need the distinction between = and == in C++.
 
except I really like both those features
and how would you overload comparison and assignment separately?
 
@DeadMG Add an extra dummy parameter!
Like pre-/postfix.
 
The only useful case of assignment as an expression I can come up with is while (!(line = readLine()).isEmpty()) ... :-)
 
in my opinion, that should totally have been operator++() and ++operator()
@FredO: I often find something like if(Derived* ptr = dynamic_cast<Derived*>(baseptr))
 
@DeadMG By return type. Comparison returns bool, assigment returns void.
 
9:35 PM
but now we can't chain assignments
 
Xeo
@FredOverflow or const this_type
 
@DeadMG T x = yis not an assignment :-) It's initialization.
 
and what if we're using expression templates?
 
@DeadMG I don't want to chain assignments! If you really want to keep that feature, you can return T&, of course.
 
Xeo
And what if the type is convertible to bool with assignment operator returning a form of this_type?
 
9:36 PM
yeah
 
@Xeo We're redesigning C++ here, right? So I would ban all but the most basic implicit conversions.
 
= and == is just fine as it is
 
needless complexity that we all got used to
 
but I absolutely definitely like things like return x == y, where comparison is an expression
 
Comparison as an expression is absolutely fine, what I don't like is assignment as an expression.
Like function(a = b) and stuff.
 
9:38 PM
yeah, but you stated earlier that you would only not need = and == to be different if you cannot have assignment and comparison expressions
 
And if (a = b) of course :) Did we really mean assignment? Or did we mean comparison, but made an error?
@DeadMG Right. Ban assignment expressions and keep comparison expressions.
Now we don't have both, only one.
 
VB works like @Fred is suggesting. Always =, no ambiguities, because there are no assignment expressions.
 
a = b;           // this is assignment
if (a = b) ...   // this is comparison
^ That's how I would imagine it.
@MartinhoFernandes Visual Basic beats C++? Who would have thought :)
 
While we are at it, let's remove subtraction. It is unnecessary and just confuses people. Also, >, <=, >=, and !=.
 
So I take it you disagree with me? :)
I would also get rid of the ++ operator and provide the following template in the standard library:
template <typename T>
void increment(T& x)
{
    x = x + 1;
}
User-defined types can then specialize the template in case incrementing could be done more efficiently.
 
9:50 PM
for(int i = 0; i != N; increment(i)); ?
 
Oh, I would get rid of the ancient for loop syntax as well, of course:
foreach i in 0 until N
 
I'd much rather keep the current syntax
 
(or something to that extent.)
 
what are you gonna do with iterators?
 
for(std::string line; std::getline(stream, line);); ?
 
9:52 PM
that kind of simplification only works for basic numerical loops, once you go over that, then it doesn't really reduce
 
My language won't have iterators in user-code, they are ugly.
I mean std::sort(foo.begin(), foo.end()); really? I want to be able to say sort(foo) or foo.sort().
 
tis true that iterators are not the most suited to their uses
 
in my language, there would not be such syntax as a.b
only one function call syntax: b a
 
Your language already exists, it is called Haskell ;-)
 
@FredOverflow What would transform (or map?) look like?
 
9:55 PM
Dunno... map(function, list) I guess?
But I'm not really designing a language, this was just some rambling on some ugly 70s syntax in C++.
 
one wouldn't be able to overload a++ and ++a separately
++ { code ... } would define the ++ operator
 
@JohannesSchaublitb a++ would implicitly be defined for all types in terms of ++a?
 
a++ would copy initialize a temporary from a and be the result of the expression a++, before calling the operator function
@FredOverflow righty!
 
@FredOverflow But does that mean I get the results in the same kind of container as what went in? Or is it in place?
 
@LucDanton Good question! My gut tends to leaving the original data intact.
 
9:59 PM
alright
 
What if I want the results in a different kind of container then?
 
what if I just recursed on the original problem? cause I could throw away a lot of N in that case, each time
 
@LucDanton A different kind of container than the input? Why would you want that, do you have a good use case for that?
 
@FredO: In C++, you can write lazily-evaluated functions that will return whatever container you try to take from them
 
Okay but what would a typical use-case for that be?
 
10:01 PM
well, for a start, you could unroll a pair<K, V> into a map
 
expression templates would be first class
 
or a vector<int> into a set
well, you can already do that, but you can also do a function at the same time
 
so you could have a type specially designed for expression templates
 
@Johannes: I've been thinking about that too
 
@FredOverflow There are the usual (and contrived) examples of the style std::copy(begin, end, std::ostream_iterator<T>(stream)), that you can adapt to std::transform(begin, end, std::ostream_iterator<T>(stream), functor)
 
10:02 PM
any expression could be transformed into a tree, and passed to functions
like D's by-name parameters
 
I guess I would have to think about that some more, don't have a perfect answer now :)
 
named parameters, absolutely
 
Scala also has call-by-name.
 
in both templates and regular functions
 
by-name parameters i mean
 
10:03 PM
@DeadMG Call-by-name and named-parameters are completely different things.
 
what's call-by-name then?
 
Call-by-name essentially means passing the argument expression (instead of evaluating it and pass the result).
 
what's that got to do with names, in any way at all ever?
 
nothing
 
ah
 
10:04 PM
In computer science, an evaluation strategy is a set of (usually deterministic) rules for evaluating expressions in a programming language. Emphasis is typically placed on functions or operators: an evaluation strategy defines when and in what order the arguments to a function are evaluated, when they are substituted into the function, and what form that substitution takes. The lambda calculus, a formal system for the study of functions, has often been used to model evaluation strategies, where they are usually called reduction strategies. Evaluation strategies divide into two basic group...
 
it means that you pass the name, not the result of the name's evaluation
 
> In call-by-name evaluation, the arguments to a function are not evaluated before the function is called — rather, they are substituted directly into the function body (using capture-avoiding substitution) and then left to be evaluated whenever they appear in the function. If an argument is not used in the function body, the argument is never evaluated; if it is used several times, it is re-evaluated each time it appears.
@JohannesSchaublitb But expressions are not names, in general.
 
well, i suspect expression-templates passing would be some mix of by-reference and by-name parameters
 
Or would you say that x+y is a name?
 
you would need to evaluate the leaf nodes of by-name parameters. but not any further
by-expression sounds ugly :)
well, by-two-names
 
10:06 PM
@JohannesSchaublitb Would you really need to? Can't you just pass the expression along with a closure?
 
I was just about to say
you could do that in C++ already
function([&]() {
    return ...;
});
 
@FredOverflow i mean, if you do process(a+b) and a and b are locals of the caller, a complete call-by-name would not capture the "a" and "b" of the caller.
so we need to at least evaluate the a and b. but not any further
passing the whole local scope of the caller seems overkill to me
but afaics it would work too
 
@JohannesSchaublitb But my gut tells me that this is exactly what happens in most call-by-name languages :) I might be wrong, of course.
 
i thought call-by-name means not binding names in the caller
void g(name n) { int a = 1; cout << n; } void f() { int a = 0; g(a); } Does this not yield 1 ?
 
Hm, so you mean f(x+y) could mean something strange if f has a local variable called x? :)
 
10:09 PM
i mean, otherwise would it not be call-by-reference?
 
The difference to call by reference is that with call-by-name, n will be re-evaluated each time in the callee. That's what enables "user-defined control structures".
 
yeah. if it is reevaluated it would indeed yield 1
i mean, n is evaluated, which would necessitate "re" evaluating a (because that's what n denotes), which would then make it an lvalue for the a in g
 
Hm... I would really like to implement this in a toy language to see how it works.
 
hm, but perhaps call-by-name impls do evaluate the leaf nodes?
 
Completely possible
 
10:13 PM
so that a is actually passed as an evaluated reference.
but if you pass a + b + c, the addition is not done. but all three variables are "set in stone" in that expression
 
Of course I would also remove references, they just add too much complexity ;-)
just kidding
 
this would still be different to both call by value and call by reference of course
so it would be a nice way of first-classing expression templates
 
How does the caller know what passing strategy is used? Does he explicitly say he wants call by name?
Like how in C# you have to say ref for call by reference (at call site)?
 
i like languages that require a '$' when reading a variable's value, and forbid '$' when requiring an lvalue.
 
Oh wait, the answer to our question was always before our eyes:
> In call-by-name evaluation, the arguments to a function are not evaluated before the function is called — rather, they are substituted directly into the function body (using capture-avoiding substitution)
In mathematical logic and computer science, lambda calculus, also written as λ-calculus, is a formal system for function definition, function application and recursion. The portion of lambda calculus relevant to computation is now called the untyped lambda calculus. In both typed and untyped versions, ideas from lambda calculus have found application in the fields of logic, recursion theory (computability), and linguistics, and have played an important role in the development of the theory of programming languages (with untyped lambda calculus being the original inspiration for functional ...
 
10:17 PM
so a '$' would pass by value, without '$' would pass by reference. i could imagine that 'a + b' would be pass-by-name, and '$a + $b' in my language would be pass by value
'$a + b' could be mixed-pass :)
 
Would a be passed by reference or by name?
Or would it make no difference?
 
that is, when the callee evaluates its parameter, 'b' is read from, and is added to a constant, which was computed from '$a' when passing the argument
 
But then you would implicitly read from b without explicitly saying so with a $...
 
sub-expressions where all nodes have a '$' would be computed completely and when passed as the sole constitute of an argument, would use pass-by-value
@FredOverflow the '$' would be needed in the callee :)
in the caller, the '$' is absent to denote "delay the reading, until the callee needs it"
 
I see.
My gut tells me that all these dollar signs could get in the way of readability. Do you have a non-trivial example program written in your language?
 
10:25 PM
it was just a silly thought. I haven't specified this language yet xD
but it seems like it could be fun to try and do it
 
Xeo
@FredOverflow Ever seen PHP?
 
@Xeo only from a distance
 
Xeo
Then you should have atleast seen the ocean of '$'
 
Oh wait, Haskell also has the dollar. a $ b c means a (b c), IIRC.
@Xeo So what does the $ sign signify in PHP?
 
Xeo
@FredOverflow Needs to be before a variable name. I think there are other symbols for arrays and functions, but I wouldn't know. :)
 
10:33 PM
i think i would allow it before a function, but it would be equivalent to omitting it
 
By the way, why does C++ have references to functions? :-)
 
Xeo
@FredOverflow Because it has references to types in general, it would be mean to exclude functions
 
9
Q: Function References

GlobalKillerSo I was just working with function pointers and I remembered that you could do this: void Foo() { } int main() { void(& func)() = Foo; func(); //::Foo(); } The obvious advantage being that references reference valid objects (unless they're misused), or functions in this case. T...

 
@Xeo Except for references to references, so why not make another exception? ;-)
 
Xeo
Oh, and no references to member functions
I'd like to see the calling syntax of that...
void (Foo::&mfptr)() = Foo::bar;
Foo f;
(f.*&mfptr)(); // ?!?
 
10:38 PM
Foo::bar is an rvalue of function type
 
Xeo
What's with foo in void (*f)() = foo;?
 
it's a function
 
@FredOverflow What do you expect pass(f) to do where pass is template<typename T> void pass(T&); and f a function?
 
or lambda
 
Xeo
Oh, and can we bind Foo::bar to an rvalue to functions then?
 
10:39 PM
no, you can't, I'm pretty sure
 
Xeo
@LucDanton Convert to function pointer first
 
it's always a little bit difficult to answer questions like "what is foo in ..." because the question is very ambiguous
 
@Xeo Then you get an non-const lvalue reference to a rvalue
 
Xeo
the funny thing, you can dereference a function as often as you want: (********foo)()
 
one cannot see from the spelling of the question whether "foo" includes or excludes any lvalue to rvalue conversion, array/function to pointer conversion and such
 
10:40 PM
you can't take an rvalue reference to functions- because they're all lvalues
 
those are invisible but still change the type and value category :)
 
Xeo
2 mins ago, by Johannes Schaub - litb
Foo::bar is an rvalue of function type
@JohannesSchaublitb Then, take those conversion in if you want. :P
 
@Johannes: Not true. void (*f)() = foo; foo must be either a function or capture-less lambda, of the correct signature, nothing else will convert to a function pointer
 
so when people claim "array names are rvalues in C most of the time", they may well be fine. but others may fight that and say they are wrong, and they are fine too. both in their own way
 
@Xeo: Well, he was wrong
 
10:41 PM
Foo::bar is neither an lvalue nor an rvalue, it is a designator, right?
 
because the name once was an lvalue before being transformed :)
 
you could argue, I guess, that the literal pointer itself is an rvalue
 
Xeo
@DeadMG What's with user-defined classes with conversion operator? :P
 
@DeadMG to what does your "Not true" refer?
 
but that's not an rvalue reference to a function, it's an rvalue reference to a pointer, which happens to point to a function
@Xeo: What valid semantics could it possibly have?
 
10:42 PM
it's correct that foo cannot be true. it can be false on most implementations, though
 
Xeo
@DeadMG Huh?
 
@Johannes: Your statement that you can't know what foo is because of array/pointer conversion and such
 
@DeadMG it is true
 
@FredOverflow Wait, I meant "qualified-id" instead of "designator" :)
 
and it is trivial to prove
 
10:44 PM
@Xeo: The Standard does not provide any way to make functions at run-time. As far as your operator goes, guess what? It has to return a function pointer or capture-less lambda
 
because... please tell me is foo an lvalue in the following? int foo = 0; int a = foo;
(the second foo, that is)
 
why, yes, I would say that foo is an lvalue
but you can't assign an int to a function pointer
nor can you have an array of function values, so no array can decay into a function pointer
 
but the spec says that it is an rvalue
 
@JohannesSchaublitb where?
 
no, it doesn't
if I said int* a = &foo; that's valid, but you can't take the address of an rvalue
you can't increment an rvalue or assign to it (for primitive types)
 
10:46 PM
"Whenever an lvalue appears in a context where an rvalue is expected, the lvalue is converted to an rvalue; see 4.1, 4.2, and 4.3."
 
int foo = 0;, after this, foo is an lvalue, of type int
except that int a = foo; does not expect an rvalue
 
how is an lvalue that is converted to an rvalue not an rvalue?
 
@JohannesSchaublitb The result of that conversion is an rvalue :)
 
there is no Standard definition saying that you can only assign rvalues to ints
 
By the way, again the spec confuses expressions with values :-(
 
10:47 PM
integers can be assigned lvalues or rvalues
 
@FredOverflow exactly. so when you say foo, do you refer to the result or to the original?
how do you denote the result?
 
@JohannesSchaublitb very good question
 
@FredOverflow in int a = foo;, foo counts as a (sub)expression
 
@Johannes: If it requires a conversion, then the result- else it refers to the original
 
So foo the lvalue expression appears in a context expecting an rvalue
 
10:49 PM
Again, I blame implicit conversions ;-) In your language, it would be int a = $foo or something.
 
@LucDanton: Why the hell would assignment expect an rvalue on the right side?
 
@FredOverflow :)
 
@DeadMG Are you being sarcastic?
 
@DeadMG Because it's an int and that's what the Standard says, isn't it?
 
well, if you have a type which is both copyable and movable, then it doesn't matter whether you get an rvalue or an lvalue
so why would you expect one over the other?
 
10:51 PM
@DeadMG Because the spec says that an rvalue is expected for scalar types.
 
damn
every time I think that I've seen all of the stupidity in the Standard, someone points out another place
 
It's not so much as stupid as backward compatible
 
i think you can derive this from 4p3
 
backward compatible with what, exactly? C didn't even have the concept of NOT copyable
 
With previous Standards
 
10:53 PM
An expression e can be implicitly converted to a type T if and only if the declaration “T t=e;” is well- formed, for some invented temporary variable t (8.5). The effect of the implicit conversion is the same as performing the declaration and initialization and then using the temporary variable as the result of the conversion. The result is an lvalue if T is a reference type (8.3.2), and an rvalue otherwise.
 
It all comes down to the fact that x can stand either for the variable x itself or for its current value. I think I'll be going back to assembly language where no such ambiguity exists :-)
 
compatibility is about not breaking existing code. If there is no existing code which depends on that part of the Standard, then you don't break anything by changing it
 
since int is not a reference type, the result of the conversion is an rvalue. and since foo originally is an lvalue, you need to apply the lvalue to rvalue conversion to convert it to an rvalue (result of the conversion)
but I think it's intuitive that in the above, the initializer is expected to be an rvalue. after all, you need the value, not some object identity
 
except it completely doesn't matter which
integer assignment can take an lvalue just fine- why would you prefer an rvalue?
 
@DeadMG You break what the observers learned before. Keeping old specifications means something else not to learn. Not to mention you don't have to make sure you didn't let a loophole in (or, don't fix it if it ain't broke).
 
10:56 PM
@DeadMG because with an lvalue you doesn't know the value
 
unnecessary WTF conversions sounds broke to me
 
Are you saying the C++ language is needlessly complex? :)
 
heh
 
I don't see the WTF with lvalue -> rvalue tbh
 
if I you ask me for some water, and I give you a bottle of water where you can't open the cap, then the bottle is completely useless for you.
 
10:58 PM
how do you decide if a base class' virtual can be const?
 
I have implementation-defined or even just undefined scissors
 
@JohannesSchaublitb Could I have some Whiskey, please?
 
@DeadMG Do you mean unspecified here?
 
@wilhelmtell What do you mean with "base class' virtual"?
 
10:59 PM
yeah
 
call-by-picture! xD
 
struct base { virtual bool poll() const; }
 
if you're just getting state about the derived class, then make it const
else, it's probably not a good idea
 
@wilhelmtell Well, you have to decide whether pool is a read-only operation or not.
 
i'd love to guarantee const, but then i employ constraints on subclasses.
 

« first day (239 days earlier)      last day (4701 days later) »