miller/docs6/docs/reference-dsl-errors.md
John Kerl 4f1424789e
Doc6 proofreads 3 (#638)
* Docs6 proofreads batch 3

* BUild-everything script for local development

* Start of glossary

* Put quicklinks atop every page, not just the base-index page

* Expanded record-heterogeneity page

* streaming page

* separators page

* vimrc doc

* separators page
2021-09-03 23:19:32 -04:00

2.3 KiB

Quick links:   Verb list   Function list   Glossary   Repository ↗
# DSL errors and transparency

As soon as you have a programming language, you start having the problem What is my code doing, and why? This includes getting syntax errors -- which are always annoying -- as well as the even more annoying problem of a program which parses without syntax error but doesn't do what you expect.

The syntax-error message gives you line/column position for the syntax that couldn't be parsed. The cause may be clear from that information, or perhaps not. Here are some common causes of syntax errors:

  • Don't forget ; at end of line, before another statement on the next line.

  • Miller's DSL lacks the ++ and -- operators.

  • Curly braces are required for the bodies of if/while/for blocks, even when the body is a single statement.

As for transparency:

  • As in any language, you can do print, or eprint to print to stderr. See Print statements; see also Dump statements and Emit statements.

  • The -v option to mlr put and mlr filter prints abstract syntax trees for your code. While not all details here will be of interest to everyone, certainly this makes questions such as operator precedence completely unambiguous.

  • Please see type-checking for type declarations and type-assertions you can use to make sure expressions and the data flowing them are evaluating as you expect. I made them optional because one of Miller's important use-cases is being able to say simple things like mlr put '$y = $x + 1' myfile.dat with a minimum of punctuational bric-a-brac -- but for programs over a few lines long, I generally find that the more type-specification, the better.