Fun fact: we've had pattern matching on 2.7 using MacroPy for a year now

https://github.com/lihaoyi/macropy#pattern-matching

@case
class Nil():
    pass

@case
class Cons(x, xs):
    pass

def reduce(op, my_list):
    with switch(my_list):
        if Cons(x, Nil()):
            return x
        elif Cons(x, xs):
            return op(x, reduce(op, xs))



On Tue, Apr 22, 2014 at 4:29 PM, Andrew Barnert <abarnert@yahoo.com.dmarc.invalid> wrote:
On Apr 22, 2014, at 15:20, Oleg Broytman <phd@phdru.name> wrote:

> On Tue, Apr 22, 2014 at 03:06:55PM -0700, Devin Jeanpierre <jeanpierreda@gmail.com> wrote:
>> Why is it that every time someone brings up switch/case, they're being
>> inspired by C and Java instead of ML or Haskell?
>
>   How many people know imperative, procedural and OO languages? And how
> many know functional or logic-based languages?

I think most people know multi-paradigm languages. C++ has similar features, even if many of them are restricted to it's compile-time template engine. Most JavaScript programs are all about passing anonymous functions to higher-order functions as callbacks, of abstractions on top of that like futures. And so on.

Anyway, people don't have a problem learning map, any, comprehensions, unpacking, or other functional-derived features in Python even if they come from C; in fact, those features are often why they don't want to go back to C. The issue is always finding the right balance, borrowing features that fit into the language well and make code easier to read but not trying to encourage recursive folds over loops or rebuild I/O around monads or pure but nondeterministic functions.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/