News for hackers. Stuff that matters.
Re:Python 3.5 to Ship with Matrix Multiplication Operator by segphault on Tuesday April 08, 2014 @03:16AM (#7551877)
There are a few handy things that I'd like to see added to Python's syntax. A dedicated operator for matrix multiplication isn't one of them.
Re:Python 3.5 to Ship with Matrix Multiplication Operator by aberrant on Tuesday April 08, 2014 @03:35AM (#7551932)
What would you like to see?
Re:Python 3.5 to Ship with Matrix Multiplication Operator by segphault on Tuesday April 08, 2014 @04:52AM (#7552200)
For starters, I really want CoffeeScript's safe accessor operator: "x?.y"

Microsoft is even reportedly considering it* for inclusion in C#, now. I think every object-oriented programming language should have it.

* http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-las...

Re:Python 3.5 to Ship with Matrix Multiplication Operator by emidln on Tuesday April 08, 2014 @08:19AM (#7552873)
I'm perfectly fine with defining get and get_in ala Clojure and using them (they work on __getitem__ supporting things, so dicts, lists, strings, most random user-level containers). I go a bit further in my codebases and implement:

    def get(obj, k, default=None):
        """ safe __getitem__ obj[k] with a default """ 
    def assoc(obj, k, v):
        """ obj[k] = v returning obj """
    def dissoc(obj, k):
        """ safe del obj[k] returning obj without k""" 
    def get_in(obj, keys, default=None):
        """ __getitem__ obj[k0][k1][kn] with a default. """
    def assoc_in(obj, keys, v, default=lambda n: dict()):
        """ __setitem__ obj[k0][k1][kn] = v. __getitem__ failures handled with default """
    def dissoc_in(obj, keys):
        """ Return obj asserting that obj[k0][k1][kn] does not exist. """
    def update_in(obj, keys, update_fn=None, default=lambda n:dict()):
        """ Update the value at obj[k0][k1][kn] with update_fn returning obj. __getitem__ failures handled by default. """ 
    def merge_with(fn, **dictionaries):
        """ Merge resolving node conflicts with fn """
    def deep_merge_with(fn, **dictionaries):
        """ Recursively merge resolving node conflicts with fn"""
as a matter of course in most of python webapp and data munging projects. They are insanely useful when working with the gobs of JSON that is common when interacting with modern web services. I really should throw the implementations into a public library at this point.
Re:Python 3.5 to Ship with Matrix Multiplication Operator by thwest on Tuesday April 08, 2014 @03:32PM (#7555458)
Why though? I'm of the opinion that the error should be handled at the place that produces the first NULL/None. Objects should be valid.
Re:Python 3.5 to Ship with Matrix Multiplication Operator by dragonwriter on Tuesday April 08, 2014 @07:16PM (#7556646)
> Why though? I'm of the opinion that the error should be handled at the place that produces the first NULL/None.

Producing NULL (or whatever the languages equivalent is) isn't an error -- if there was an error, it would be throwing an exception, not returning NULL. The idea of "do this chain of operations propagating nulls encountered at any point" is reasonably useful.

Re:Python 3.5 to Ship with Matrix Multiplication Operator by thwest on Tuesday April 08, 2014 @07:46PM (#7556790)
I just hate NULL standing in for a boolean notion of existence, I'd rather see a separate boolean member indicating the validity of the other member (string middle_name; boolean has_middle_name;). Or in a strongly typed language an Option/Maybe type. Just assigning things NULL sometimes has the problem of people looking at the object and assuming everything will always be populated.
Re:Python 3.5 to Ship with Matrix Multiplication Operator by shadowmint on Tuesday April 08, 2014 @03:42AM (#7551955)
multi-line lambdas.
Re:Python 3.5 to Ship with Matrix Multiplication Operator by jdpage on Tuesday April 08, 2014 @04:05AM (#7552050)
Not happening, because it would mean multi-line function arguments, which have been declared "ugly".

http://legacy.python.org/dev/peps/pep-3099/

Re:Python 3.5 to Ship with Matrix Multiplication Operator by EliAndrewC on Tuesday April 08, 2014 @11:55AM (#7554153)
Guido explains in an old blog post (http://www.artima.com/weblogs/viewpost.jsp?thread=147358) that he considers all of the possible implementations of multi-line lambdas to be un-Pythonic:

> But the complexity of any proposed solution for this puzzle is immense, to me: it requires the parser (or more precisely, the lexer) to be able to switch back and forth between indent-sensitive and indent-insensitive modes, keeping a stack of previous modes and indentation level. Technically that can all be solved (there's already a stack of indentation levels that could be generalized). But none of that takes away my gut feeling that it is all an elaborate Rube Goldberg contraption.

Re:Python 3.5 to Ship with Matrix Multiplication Operator by Noelkd on Tuesday April 08, 2014 @03:53AM (#7552013)
Wouldn't you just define a function in that case? Guido has mentioned[1] that he isn't a fan of lambda functions.

[1] http://www.linuxjournal.com/article/2959