Here's a neat test of programming language expressiveness: Can you write a function PrintXY taking an integer n>=0 that prints all strings of length n containing only the characters 'X' and 'Y'? Can you do it without recursion, and without assuming n<=64? Is it readable?
-
-
New expressive power comes from our ability to nest choices inside of loops, where each iteration explores all choices. Then we can variably "exponentiate", and write PrintXY as:pic.twitter.com/loFkBD2RaC
Show this thread -
Is this a quirky, special-case language feature? Definitely not; it has well-defined semantics and increases the expressive power of loops. And it's what 14-year-old me intuitively tried to do in Apple BASIC.
Show this thread -
There are many interesting solutions in this thread. The C and JavaScript solutions seen akin to mechanical devices that crank out solutions. One is an astonishingly short Haskell composition of library functions:https://twitter.com/tikhonjelvis/status/1265453175219183616?s=20 …
Show this thread -
There is generally a barrier to reading these solutions. In one case you have to run through the behavior of imperative code in your head to understand what it does. In another you have to understand the near magical incantation of pointfree function compositions.
Show this thread -
The more a solution can resemble a simple recitation of the problem to be solved, and rely on the compiler to generate the code, the better for ease of reading and writing code.
Show this thread
End of conversation
New conversation -
-
-
Is `a...b` inclusive or exclusive of `b`?
-
It has to be inclusive if it's to be non-confusing and to work for any finite ordered values, such as 'A'..'Z'. Thus if used on loops, you'd write for(i=0..count-1).., which is ugly but fortunately uncommon if loops also support for(a:MyArray) iteration without indices.
- 5 more replies
New conversation -
-
-
You mean like the GCC-supported case range? https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html … Those are very handy in some cases.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.