
The Language of Choice - pyb
https://codewords.recurse.com/issues/four/the-language-of-choice
======
falcolas
The code out of GitHub doesn't appear to work, at least not how you'd hope it
would. Couldn't follow the article from the command line without writing the
code myself.

    
    
        ~/src/github.com/darius/mccarthy-to-bryant (master)$ python
        >>> from nway_logic import *
        >>> A, B = Variable('A'), Variable('B')
        >>> A
        A
        >>> B
        B
        >>> const0 = Constant(0)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        NameError: name 'Constant' is not defined
    
        ~/src/github.com/darius/mccarthy-to-bryant (master)$ python
        Python 2.7.10 (default, Jul 13 2015, 12:05:58)
        [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
        Type "help", "copyright", "credits" or "license" for more information.
        >>> from dd import *
        >>> A, B = Variable('A'), Variable('B')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          File "dd.py", line 27, in Variable
            return build_node(rank, tuple(map(Constant, range(arity))))
          File "utils.py", line 7, in memoized
            result = memoized._memos[args] = f(*args)
          File "dd.py", line 34, in __init__
            for b in branches: assert rank < b.rank
        AssertionError
        >>>

~~~
abecedarius
For the first, the README says it's logic.py and not nway_logic.py that has
the article's code. (The latter is a generalization that was actually written
first.) logic.py was extracted from the text, and the transcript tested
against it.

I've just backported the renaming to Constant into nway_logic, and that
example should work unaltered now -- thanks!

For the second, the interface to the decision diagrams does not use variables
with names, as explained under 'Systematic succinctness' and demoed in
make_alu_inputs() -- I aimed for the simplest code that shows the ideas. But I
think you're right that bdd.Variable should've been called something different
from logic.Variable.

~~~
falcolas
logic.py did not exist in my checkout, which is why I ended up trying
nway_logic instead.

~~~
abecedarius
Ah, I'm sorry about that.

Product of sadly declining ambitions: first for SVG toys, which I'm
incompetent at; then yesterday I was looking into converting the text into an
iPython notebook to provide an easier way to interact with the code, and that
turned out to be too hard under the deadline. I ended up pushing the article's
code into this repo shortly after the article went live.

~~~
falcolas
No problem, thanks for fixing it. I'll be diving back into the article with
the code, since it makes for some really interesting reading.

~~~
abecedarius
Thanks, and hope you like it!

------
thoastbrot
How could he write that article without a sole mention of prolog?

~~~
abecedarius
Author here. I like Prolog, and you might enjoy my
[https://github.com/darius/pythological](https://github.com/darius/pythological).
Here's an excellent free book: [http://www.mtome.com/Publications/PNLA/prolog-
digital.pdf](http://www.mtome.com/Publications/PNLA/prolog-digital.pdf)

But the first draft of the article was already stuffed too full without even
trying to go past propositional logic; it had to be cut, not expanded.

