Thread: Can you count to ten?

  1. #16
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Yarin View Post
    Haskell:
    Code:
    main = print([1..10])
    Ha! That's so easy lol.

    Okay, I just suck at Haskell T_T

  2. #17
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by MutantJohn View Post
    Okay, I just suck at Haskell T_T
    I'd imagine that's probably true for most of us.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #18
    Registered User
    Join Date
    Oct 2016
    Location
    Wales, UK
    Posts
    12
    Lua :

    Code:
    for i=1,10
    do
    print(i)
    end

  4. #19
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    In a language that may not be named:
    Code:
    ++++++++[>++++++>++++++<<-]><+++++++++[>+.<-]>>+.-.
    Last edited by stevesmithx; 10-05-2016 at 10:10 PM.

  5. #20
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Here is a version with newline
    Code:
    ++++++++[>++++++>++++++>+<<<-]>>>++<<<+++++++++[>+.>>.<<<-]>>+.-.
    I had to "cheat" for "10" in both versions but oh well..

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Overdone recursion in C++:
    Code:
    #include <iostream>
    
    template<int N>
    class Count
    {
    public:
        Count()
        {
            Count<N-1>();
            std::cout << N << std::endl;
        }
    };
    
    template<>
    class Count<1>
    {
    public:
        Count()
        {
            std::cout << 1 << std::endl;
        }
    };
    
    int main()
    {
        Count<10>();
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #22
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Elkvis View Post
    I'd imagine that's probably true for most of us.
    Lol seriously though. I sat down and really, really tried to learn it. I'm now convinced the people that love it are actually just experiencing Stockholm syndrome. I worked through the stuff of how functions and lists can operate as an applicatives and then I was like, "I'm over-complicating what's basically a nested for-loop in C"

  8. #23
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by MutantJohn View Post
    Lol seriously though. I sat down and really, really tried to learn it. I'm now convinced the people that love it are actually just experiencing Stockholm syndrome. I worked through the stuff of how functions and lists can operate as an applicatives and then I was like, "I'm over-complicating what's basically a nested for-loop in C"
    I don't really believe Haskell or other crap similar to that (like OCaml, these niche langauges...) is practical or useful. I mean that in the sense of "why would you choose this over something else more recognized and readable that can do it just as fast".

    In general, kind of resent the idea of using languages like that just for the sake of being different, as opposed to it actually being useful.
    Last edited by Epy; 10-06-2016 at 01:03 PM.

  9. #24
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Epy View Post
    I don't really believe Haskell or other crap similar to that (like OCaml, these niche langauges...) is practical or useful. I mean that in the sense of "why would you choose this over something else more recognized and readable that can do it just as fast".

    In general, kind of resent the idea of using languages like that just for the sake of being different, as opposed to it actually being useful.
    The problem is, someone realized that you can apply category theory as a means of expressing programs. The biggest issue with this is that, well, math sucks. No one wants to reason about their code as categories and then how they relate to each other through the use of functors, here "functor" is the formal definition of mapping of values and their morphisms in a category to a separate category.

    The terms "monoid in the category of endofunctors" only really make sense to people who are really, really into math. I don't think it's a useful programming construct at all. It's almost abhorrent, the amount of extra cognitive overhead that's applied to relatively simple code.

    FP did bring some useful things to the table though, namely higher-order functions.

  10. #25
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    I do like FP, I started off with Lisp after all. Just some programming languages look more like a puzzle than elegant / readable IMO. Unnecessary unless just messing with it as a hobby IMO.

  11. #26
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Okay, I've come back to say that I've done it!
    I can do it on my own now:
    Code:
    main = foldr((>>) . putStrLn . show)(return ())([1 .. 10]);
    Took me 4 weeks to learn how to print 1 through 10 in Haskell lol but I've done it and I understand it! I understand how you form monads out of endofunctors and the two natural transformations and how they form monoids over categories themselves. Bloody Hell...

    This is also ridiculously inefficient compared to imperative languages as well. Category theory is fun to learn but gosh darn, some things it's apparent that the "dumb" way is clearly the "better" way.

  12. #27
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Sorry to interrupt the serious conversation, but I realised this video from a Japanese game show has not been posted.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #28
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    277

    Red face

    Lucas would have done it like this, probably:

    Code:
    #include <stdio.h>
    int main()
    {
        for(int tmp, a = 0, b = 1; b <= 10; tmp = 2 * b - a, a = b, b = tmp)
            printf("%d\n", b);
    }

  14. #29
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Code:
    '(1 2 3 4 5 6 7 8 9 10)
    Which is almost a quine, if not for the ' (unquote) character.

    BTW, that is Scheme code which will evaluate to the list of integers from 1 to 10. In Scheme, code is data and vice-versa (mostly).
    Last edited by MacNilly; 11-22-2016 at 01:34 AM.

  15. #30
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Actually, most Scheme code can evaluate to itself which makes writing quines in Scheme mostly trivial if you can account for the unquote operator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Uppercase/Lowercase/Word COunt/Char count
    By Charak in forum C Programming
    Replies: 7
    Last Post: 02-23-2011, 08:16 AM
  2. Even I Can Count Better Than That...
    By pianorain in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 12-02-2005, 07:17 PM
  3. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM
  4. Replies: 2
    Last Post: 05-05-2002, 01:38 PM

Tags for this Thread