Domain Specific Language Examples

See also my other programming languages links.

R

Starting with this data.csv file, start R and:

coursedata <- read.csv(file="data.csv", head=TRUE, sep=",")
coursedata
summary(coursedata)
summary(coursedata$Final)

hist(coursedata$Final, xlim=c(0,50))
fit <- lm(coursedata$Final ~ coursedata$Assign)
summary(fit)

plot(coursedata$Assign, coursedata$Final)
abline(fit)

But, compare Python code that does the same things with Pandas and matplotlib.

LaTeX

Again, working with my example.tex file. The old way to turn this into a PDF:

latex example
dvips -Ppdf example
ps2pdf example.ps example.pdf

The newer way:

pdflatex example

When I process that input file, I get this PDF output.

Graphviz

For exercise 9, I included this graph:

directed graph represented by knowledge base

It was produced by Graphviz from this DOT source file with the commands:

dot 9-graph-src.dot -Tpng -o 9-graph.png
dot 9-graph-src.dot -Tgif -o 9-graph.gif
dot 9-graph-src.dot -Tsvg -o 9-graph.svg

(which produce PNG, GIF, and SVG output, respectively). You can also look at the source for the exercise 10 graph.

Shell scripting

As an example of a BASH script, my leading-tabs.sh finds and prints all Python files in the current directory that have a line that starts with a tab character.

The script uses find to get all regular files (not directories, etc.) in the directory that are named like *.py. Then each of those filenames is given to a sub-script that uses grep to check if there are leading tabs. If there are, the filename is printed.


Copyright © , last modified 2012-07-25.