1. 1

    This talk is such a joke!

    I bet I could do a better job of re-adding the print statement to Python. I’d probably implement some equivalent of a reader macro or patch the part in the parser where it “falls off the end.”

    1. 1

      He’s replaced the referenced section on the book website. It’s available from archive.org:

      https://web.archive.org/web/20141205223016/http://c.learncodethehardway.org/book/krcritique.html

      The critique above seems a bit thin and comes across a bit pseudo-theoretical—is there any additional context?

      1. 3

        This is an awesome thread!

        This week, I hope to use my nasty http://github.com/dutc/didyoumean assembly-patching hack to make two recent extensions to Python 3 available to folks to play with.

        The first extension is decoupling scope-as-visibility from scope-as-evaluation-context, allowing constant expressions to be evaluated either one scope higher or in the highest-level scope. Since we can probably safely assume module-import can occur at any time before its contents' runtimes, this could allow us to encode certain static checks and static optimisations into our code.

        Thus, the following would immediately raise a ValueError (day is out of range for month.)

        >>> from datetime import date
        >>> class Foo:
        >>>  def bar(self):
        >>>    return !!date(2014, 2, 30) # evaluate at top scope
        

        Similarly, we could fix a specialisation to a fast path in the below (for the lifetime of the programme):

         >>> def f(x, y):
         >>>  def helper():
         >>>    return !{(int, int): fast_path_ii, (float, float): fast_path_ff}.get((type(x), type(y)), slow_path) # evaluate one scope up
        

        The second extension adds ast-literals to Python 3.

        >>> e = $(x+y)*w+x
        >>> e
        sym(+, [sym(×, [sym(+, [sym(x), sym(y)]), sym(w)]), sym(x)])
        >>> e(x = $w+3) # bind x
        sym(+, [sym(×, [sym(+, [sym(+, [sym(w), 3]), sym(y)]), sym(w)]), sym(+, [sym(w), 3])])
        >>> e(x = $w+3)(w = 10) # bind x & w
        sym(+, [sym(×, [sym(+, [sym(+, [10, 3]), sym(y)]), 10]), sym(+, [10, 3])])
        >>> e(x = $w+3)(w=20)(30) # bind x, w, y
        sym(+, [sym(×, [sym(+, [sym(+, [20, 3]), 30]), 20]), sym(+, [20, 3])])
        >>> e(x = $w+3)(w=20)(30)() # bind x, w, y, & evaluate
        1083
        

        Not sure if either of these are actually useful, but they are fun exercises!