Tuesday, 31 March 2015

Caryatid

In "Stranger in a Strange Land" Heinlein talks about a Rodin sculpture called "The Fallen Caryatid Carrying her Stone". One of the female characters says that when she first saw it she thought it was horrid, but over time she came to the conclusion that it was the most beautiful thing she had set eyes on.

I'm not suggesting that my work is of the same quality as one of Rodin's best sculptures, but something I’ve been working on recently has the same combination of horror and beauty.

you can safely skip the rest of this article if you’re not a computer programmer

If you are writing a programming language, you tend to have three distinct pieces: A lexer, which splits the source code into tokens, a parser which takes the stream of tokens and forms an abstract syntax tree, and something that walks the tree and produces object code.

I'm working on a JSONRPC web service and one of its parameters is an arbitrary Boolean predicate. I couldn't be bothered with the lexer and parser and just typed an AST in JSON to get me started. As the project has progressed, instead of defining a syntax and writing the lexer and parser, my boss and I have realised that the AST is as good a syntax as any, and the caller can pass one to us. Eg.

"filter":{
                "AND":[
                                {predicate},
                                {predicate},
                                "OR":[
                                                {predicate},
                                                {predicate},
                                                "NOT":{predicate}
                                ]
                ]
}

Richard "Reverse Martian Notation" B

No comments:

Post a comment