Lua :
Code:for i=1,10 doprint(i)end
In a language that may not be named:
Code:++++++++[>++++++>++++++<<-]><+++++++++[>+.<-]>>+.-.
Last edited by stevesmithx; 10-05-2016 at 10:10 PM.
Here is a version with newline
I had to "cheat" for "10" in both versions but oh well..Code:++++++++[>++++++>++++++>+<<<-]>>>++<<<+++++++++[>+.>>.<<<-]>>+.-.
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>(); }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
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.
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.
Okay, I've come back to say that I've done it!
I can do it on my own now:
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...Code:main = foldr((>>) . putStrLn . show)(return ())([1 .. 10]);
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.
Sorry to interrupt the serious conversation, but I realised this video from a Japanese game show has not been posted.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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); }
Which is almost a quine, if not for the ' (unquote) character.Code:'(1 2 3 4 5 6 7 8 9 10)
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.
Actually, most Scheme code can evaluate to itself which makes writing quines in Scheme mostly trivial if you can account for the unquote operator.