« first day (525 days earlier)      last day (4648 days later) » 

23:04
im trying to find the largest prime factor of a big number, I know that's the smallest factor is indeed prime, but how about the largest. should I really find all the prime numbers that divide it. or there is an easy way.
anyone ?
Hehe, I just found the first use case for a labeled continue in Java:
outer:
for (int[] line : lines)
{
    for (int i : line)
    {
        if (getPlayer(i) != _player) continue outer;
    }
    return true;
}
return false;
Can it be done as "nicely" in C++?
@FredOverflow looks like goto
@Abyx Well, goto would restart the loop, as opposed to continue which continues the loop :)
can someone look at my question above,
1. Yes, I *can* look at it.
2. I *looked* at it.
3. I don't know the answer :(
Xeo
Xeo
23:17
@FredOverflow set the label above the inner loop?
That would not increase the outer "loop counter".
Xeo
Xeo
oh, wait
Yeah, I see now
Solution: goto after the return true;
Xeo
Xeo
Meh, I wanted to go for lambda. :(
for (int[] line : lines)
{
    for (int i : line)
    {
        if (getPlayer(i) != _player) goto after;
    }
    return true;
    after:;
}
return false;
Xeo
Xeo
23:19
Oh, wait
Xeo
Xeo
Nevermind
The inner loop can return too. Meh
Well, you could probably replace the whole outer loop body with a call to std::all_of :)
@AlexDan every prime factor, including the smallest, is necessarily prime. to find the largest you generally have to find all factors. there is no easy way for the general case: all modern encryption relies on there being no easy way.
does this work? for(auto &&x : alias<int[][3]>{{1, 2},{3,4}}) ...;
23:20
anyway, this code is too complicated, inner loop should be extracted into separate function
And the outer loop itself can probably replaced with a call to any_of :)
I once did something similar in Haskell, and it was only 1 line of code.
@Abyx I don't think that 6 lines is too complicated. I think the code is too low-level. It doesn't read nicely.
i wonder whether one can create a list comprehension library for c++
I'm so glad Scala got rid of that stupid for(init;condition;update) syntax. It's simply too low-level.
@FredOverflow What syntax would you have instead?
@FredOverflow it does more than one thing and have non-trivial logic
23:23
@DeadMG In the rare cases where you actually need that, you use a while. But in most cases, you would use for comprehensions in the form for (x <- list) or something (no Scala expert here).
For simple counting, you say for (i <- 1 to 10).
hmm
@FredOverflow i doubt
@CheersandhthAlf the number is so big, here is an example :projecteuler.net/problem=3
@FredOverflow Why not simply use a library function with a lambda for such things?
1 to 10 is just syntactic sugar for (1).to(10) which yields a sequence, and that works with for comprehensions.
23:26
it works just as well with c++
(1_).to(10);
@CheersandhthAlf Integer factorization can be done easily with a quantum algorithm. Of course, that hardly counts as "modern", more like "super-futuristic"
@DeadMG Maybe it is a library function. Scala is so fucking generic and customizable I couldn't tell the difference :)
lol
unfortunately the parens are required (llvm.org/bugs/show_bug.cgi?id=12344)
@DeadMG Scala containers have a foreach method which accept lambdas, if you prefer that.
23:29
well, I generally think that having such things in the language is a waste when a well-designed library can cope with it just fine
for comprehensions do more than a foreach, though. Do you know what a list comprehension is in Haskell? Scala's for comprehensions are more general, because they work for any monad.
monad "comprehension". you mean with guards
I still don't think that it can't be done fine with a library
I've not seen any displayed comprehension that's meaningfully different to what you can do with, say, LINQ
Again, I don't know if for comprehensions are built-in or standard library. And I couldn't care less :)
lol
23:31
Isn't LINQ also built on monads?
well, they'd have to be built-in if you want to have special syntax for them
LINQ is built-in in c#
it is if you want to type them out using contextual keywords
Sure, but "SelectMany" is "bind", right?
but if you write the expression as like x.Where(...).Select(...), then it isn't
@FredOverflow I have no idea
23:33
Well, in Scala you can omit the periods and the parenthesis. object.method(param) is the same as object method param.
i have no idea about SelectMany
Pretty sure Erik Meijer or Brian Beckman mentioned that at least once.
@FredOverflow Eh, I don't find it meaningful, I can't tell at a glance which identifiers are parameters, and which are expressions
but in any case, I don't see the advantage of removing them
Because 1 + 2 looks a lot nicer than (1).+(2)? :)
lol
23:35
Seriously, that is the reason. Scala doesn't have operator overloading but allows methods named + and such.
eh
that's kinda silly :P
for the delimiterless syntax, I can never understand how you can tell the difference between f(g(x)) and f(g, x)
Oh, leaving out the parens only works for methods with one argument in Scala IIRC.
So you can't abbreviate o.m(x, y)
The problem doesn't exist in Haskell because every function is unary. There are no functions that take more than one argument.
yay currying
how on earth can that work?
how could you even write simple addition as a unary function?
add x = \y -> x + y
where on earth does y come from if it's not a parameter?
23:38
y is the parameter of a lambda that is returned from add
that's epsilon reduction.
also known as currying, right?
I only know it by the name "currying".
In mathematics and computer science, currying is the technique of transforming a function that takes multiple arguments (or an n-tuple of arguments) in such a way that it can be called as a chain of functions each with a single argument (partial application). It was discovered by Moses Schönfinkel and later re-discovered by Haskell Curry. Because of this, some say it would be more correct to name it schönfinkeling. Uncurrying (also known as counter-currying) is the dual transformation to currying, and can be seen as a form of defunctionalization. It takes a function f(x) which returns a...
or wait. perhaps epsilon reduction is going from "foo x = bar x" to "foo = bar"
23:40
right
but that doesn't solve the ambiguity
because I could still mean f(g(x)) or f(g)(x)
@DeadMG delimiterless function calls work by associativity.
"a b c" means "(a b) c" rather than "a (b c)" in haskell
so function application is left associative
right, function application is left-associative.
Damnit, Johannes is always 1 second faster than me!
On the one hand, Haskell eliminates most noisy periods and parenthesis, and on the other hand, it invents all kinds of crazy operators like >>= :)
though you have "$" available with very little precedence, so you can say "a $ b c" to mean "a (b c)", because "$" is "$ a b = a b"
23:43
eh
I think I'm happier with periods and parenthesis than implicit associativity
or should it be "($) a b = a b", i forgot
if it is non-alphanumeric or something, you need to parenthesize it to be a prefix operator. otherwise it's infix by default
std::function<int(int)> add(int x)
{
    return [=](int y) { return x + y; };
}
int example = add(2)(3);
Can I return a lambda without std::function?
not really
:(
[=] is pronounced "tie fighter", right? :)
lol
ironically, I think you could, strictly, do it with a lambda
as the return type is inferred
23:52
Anyway, something like the above is generated when you write add x y = x + y in Haskell.
auto add = [](int x) { return [=](int y) { return x + y; }; };
auto add = [](int x) { return [=](int y) { return x + y; }; };
lol
See, Johannes is always 1 second faster!
he just copied it -.-
lol
gotta love a line of code that ends in ; }; };
23:53
wait, no. he mentioned it before I posted it
i didn't notice him mentioning it. weird
selective perception
auto triple_add = [](int x) { return [=](int y) { return [=](int z) { return x + y + z; }; }; };
yeah sometimes i think of something and then i notice it
Now do n-add with variadic templates!
nah
what a waste of compiler effort
23:55
So Wide won't have them?
what, unary functions, or lambdas?
or variadic templates?
Variadic Templates
no, absolutely I won't
#define FDEF(N, P, ...) auto N = [&] P __VA_ARG__
templates are one of the stupidest ideas I ever heard of
23:55
lol
As long as Wide doesn't have variadic tempaltes, I'll call it "Narrow".
6
oh come on
FDEF(foo, (int a), {
  cout << a << std::endl;
});
xD
templates are functions, but they invented totally different syntax and semantics for them for absolutely no purpose
okay so you have variadic functions?
there's no reason for templates to exist if you have general metaprogramming
23:57
Templates != metaprogramming.
well, technically, no, but I do have tuples and tuple unpacking, which is arguably essentially equivalent
What is the signature of sort in Wide?
@CatPlusPlus They are identical.
what is n-add ?
23:57
template<typename T> class X == type X(type T) { return class { ... }; }
@DeadMG That is your signature of sort? :)
@FredOverflow No, I'm just demonstrating the equivalence.
And template <typename I> void sort(I, I, I);?
@DeadMG But sort is not a class template.
Or whatever.
23:59
@FredOverflow Sure. So instead of returning a class, it returns a function.
Boilerplate.
I would really like to see an example. How about Swap?

« first day (525 days earlier)      last day (4648 days later) »