I've got an idea for a new kind of puzzle and would like to ask if it's OK first. It's a bit different than the usual code-golf kind of question. It doesn't ask for the shortest solution, or something funny/silly like the troll questions, but actually for something semi-useful. I'll give an example first, and then describe the general idea:
Example: Implement multi-line lambdas in Python. Guido van Rossum said it couldn't be done, prove him wrong. Your solution should allow something like:
>>> f = multilinelamba("hour", """ ... if hour > 20 or hour < 6: ... print "Good night" ... else: ... print "Hello world" ... """) >>> f(10) ... 'Hello world'
Your solution should be as close as possible to the behavior of real
lambda. The actual syntax or way of implementation doesn't matter (e.g. define a function, write a preprocessor, ...). You get bonus points:
- If your solution captures outside variables in a closure, like real
- For correct handling of exceptions in the multiline lamba
- (and so on, a checklist of objective criteria or 'unit tests' to judge)
I posted this question a while ago on Stack Overflow: Recipe for anonymous functions in python?, but it received a lot of hate. People didn't answer it, but told my why it was a bad idea, and I had to justify myself and put up big disclaimers. So now I'm trying something different, I'm posing it not as a SO question, but as a programming riddle. Explicitly not looking for a solution for production code, but just for fun. That doesn't mean I'm looking for silly solutions - they should be well-engineered and in principle usable. I have a couple of these questions where tinkering is required, and I'm really curious to see clever solutions, but I'm afraid of posting them on SO for obvious reasons.
I personally don't really care for rating the answers, and would be happy with two or three interesting submissions per question without picking a winner. But it seems the community feels strongly about having objective winning criteria, so I propose a check list of "tests" like above that the solution must pass, the more it passes the better.
One think I'd like to add is that the answers should be compact enough to fit in an answer. You may link to a repository, if your solution lead to something cool and useful, of course, but the core idea (and basis of rating, if desired) should be presented succinctly.
Finally, it should be a question that doesn't fit directly on SO, so no straightforward programming questions, but rather hackish "I wonder if it could be done?" kind of challenges. The kind where people refuse to answer, and say "don't" or "what are you trying to accomplish?".
As for a tag name, I have no great idea. Maybe something like
As Guido said, "Language Design Is Not Just Solving Puzzles", but solving puzzles is fun!