• Good point. This method is new to me. Thanks for the explaination.

  • How this two tests can be true simultaneously?

    And why do you think 2 different expressions can't have 2 different values at the same time?

  • //auto a = add(1)(2); a(3); a == 3

    //auto a = add(1)(2); a(3) == 6;

    How this two tests can be true simultaneously?
    Which one is mistake?

  • Interesting kata. Help me learn more Python
    Thanks.

  • No I can't.
    I tried to use operator() and operator int in a class to simulate a function but it just does not compile. Wonder if someone compiles.

  • My solution works with test from c++ < cassert > for example

    assert(add(1)(2) == 3);
    assert(add(1)(2)(3) == 6);

    but with kata tests:

    In file included from main.cpp:1:
    In file included from /usr/local/include/igloo/igloo_alt.h:10:
    In file included from /usr/local/include/igloo/igloo_framework.h:22:
    In file included from /usr/local/include/igloo/external/snowhouse/snowhouse.h:4:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/fluent.h:9:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/expressionbuilder.h:9:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/../constraints/constraints.h:9:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/../constraints/containsconstraint.h:12:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/../constraints/expressions/expression.h:9:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/../constraints/expressions/notexpression.h:9:
    /usr/local/include/igloo/external/snowhouse/stringize.h:53:56: error: use of overloaded operator '<<' is ambiguous (with operand types 'std::ostream' (aka 'basic_ostream') and 'const add2')
    static const bool value = sizeof(check(std::cout << x)) == sizeof(yes);
    ~~~~~~~~~ ^ ~
    /usr/local/include/igloo/external/snowhouse/stringize.h:103:51: note: in instantiation of template class 'snowhouse::typing::is_output_streamable' requested here
    return detail::DefaultStringizer<T, typing::is_output_streamable::value>::ToString(value);
    ^
    /usr/local/include/igloo/external/snowhouse/stringize.h:94:27: note: in instantiation of member function 'snowhouse::Stringizer<add2, char>::ToString' requested here
    return Stringizer::ToString(value);
    ^
    /usr/local/include/igloo/external/snowhouse/assert.h:32:39: note: in instantiation of function template specialization 'snowhouse::Stringize' requested here
    str << "Actual: " << snowhouse::Stringize(actual) << std::endl;
    ^
    /usr/local/include/igloo/external/snowhouse/assert.h:89:25: note: in instantiation of function template specialization 'snowhouse::DefaultFailureHandler::Handle<snowhouse::EqualsConstraint, add2>' requested here
    FailureHandler::Handle(expression, actual, file_name, line_number);
    ^
    main.cpp:33:17: note: in instantiation of function template specialization 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That<add2, snowhouse::EqualsConstraint >' requested here
    Assert::That(add(1), Equals(1));
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:189:7: note: candidate function
    operator<<(int __n);
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:166:7: note: candidate function
    operator<<(long __n)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:170:7: note: candidate function
    operator<<(unsigned long __n)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:174:7: note: candidate function
    operator<<(bool __n)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:178:7: note: candidate function
    operator<<(short __n);
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:181:7: note: candidate function
    operator<<(unsigned short __n)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:192:7: note: candidate function
    operator<<(unsigned int __n)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:201:7: note: candidate function
    operator<<(long long __n)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:205:7: note: candidate function
    operator<<(unsigned long long __n)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:220:7: note: candidate function
    operator<<(double __f)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:224:7: note: candidate function
    operator<<(float __f)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:232:7: note: candidate function
    operator<<(long double __f)
    ^
    /usr/local/include/igloo/external/snowhouse/stringize.h:34:9: note: candidate function
    tag operator<<(std::ostream&, any const&);
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:517:5: note: candidate function [with _Traits = std::char_traits]
    operator<<(basic_ostream<char, _Traits>& __out, char __c)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:511:5: note: candidate function [with _CharT = char, _Traits = std::char_traits]
    operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:523:5: note: candidate function [with _Traits = std::char_traits]
    operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ostream:528:5: note: candidate function [with _Traits = std::char_traits]
    operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
    ^
    1 error generated.

  • I did it! Thank a lot.

  • This comment is hidden because it contains spoiler information about the solution

  • This comment is hidden because it contains spoiler information about the solution

  • I only solved the python one but am a JS dev. So out of curiosity does it fail if you do strict comparison using === ?

  • in fact, the premise of the question is not right

    "add(1)(2);
    // returns 3"

    No. It is not. This returns a function.

    In the tests, it is the == operator that does the conversion, as you can read it here:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality

    "If the operands are of different types, try to convert them to the same type before comparing:
    When comparing a number to a string, try to convert the string to a numeric value.

    • If one of the operands is Boolean, convert the Boolean operand to 1 if it is true and +0 if it is false.
    • If one of the operands is an object and the other is a number or a string, try to convert the object to a primitive using the object's valueOf() and toString() methods."
  • This kata made me RTFM and learn about classes and dunders in Python :D

  • Loading more items...