## (Mostly) Imperative Packrat Parsing

I’ve been tinkering with monadic parser combinators combined with continuations (see Monads, Mother of All), but my latest toy simplifies all that by using PEG grammars. PEGs and CFGs are nearly interchangable for most parsing of computer languages, and can be parsed in linear time and space by packrat parsing — parsing with backtracking, but …

## Non-determinism from generators

UPDATE(7/3/2013) I’ve found an earlier use of this technique written about on a blog, Valued Lessons – Monads in Python from 2008. Please read it too! ~~~ I was tinkering a bit tonight with simulating nondeterminism a-la McCarthy’s Amb operator — in Python. This is peculiar as Amb is usually implemented using either first class …

## Diversion

A little Python snippet, good for a diversion. I couldn’t fit it into a tweet though: s=[];op=dict((o,eval(‘lambda a,b:b%sa’%o)) for o in ‘+-*/%’) while not any(s.append(op[w](s.pop(),s.pop())if w in op else float(w)) for w in raw_input().split()): print ‘=’,s[-1] Just a simple 4-function RPN calculator, accepting input from console: 1 = 1.0 2 2 + = 4.0 1 …

## Some parser combinators for Python

I’ve got two parser combinators today for you to play with, both whipped up this evening from pieces of earlier experiments.

## Bondage and Discipline Python

Python has an identity crisis sometimes. It starts with the premise, from Guido’s prior work on ABC, to make a simple but easy to understand language. But then turns around and cries out “one way to do it“, leaving the programmer perplexed as to how Guido van Rossum thought we should do things. For example, Guido hates …

## Eval in Python

I’ll just leave this here for you: Wait what. Python compiles? That is correct. CPython and PyPy (the implementations worth caring about currently) are in fact creating a code object from the string you pass to exec or eval before executing it. And that’s just one of the things many people don’t know about the exec statement. …

## Quickrefs for Python and Vim

More quick reference booklets: Vim PocketMod draft 1 (new) Python PocketMod draft 1 (new) Scheme PocketMod draft 3 (updated) I don’t really need the qr for Python, but I thought it might be good to have ready should a friend a coworker wish to start learning Python. As for Vim, the reference is certainly terrible …

## Memoizer revisited – Python

A conversation with a coworker entertained the idea of giving a talk on dynamic typed programming language patterns to a group of C++ developers — not that we’re experts, but as part of my team’s initiative for continued education for our engineers, individuals go out and research different ideas, techniques, technologies and present the results …