Monthly Archives: January 2015

The Philosophy of Andl

The philosophy of the Andl language includes the following considerations.

  1. Consistent use of syntax. Things that do similar things should look similar, and vice versa.
  2. Functional in style (not procedural or OO). A language of expressions with (almost) no side-effects, which can support either lazy or eager evaluation. Everything that looks like a value could actually be an expression.
  3. Lexical scoping. Predefined->catalog(s)->argument(s)->current tuple(s)->local. No scope resolution operators, just renaming and aliases. Scoping reads left-to-right, consistent with infix notation.
  4. Few or no reserved words. System library functions have names, but can always be overridden by user definitions.
  5. Not too many arcane symbols. They just take too much explaining.
  6. Lexical: any legal characters are permitted in an identifier and any legal characters can be used to construct a literal character string (but control characters are not recognised). Strings concatenate. Special quoting conventions for identifiers, Unicode strings, time literals.
  7. Types: the native abstract types are logical, number, character, time and binary. All SQL types are accepted, but are converted accordingly.
  8. The compiler is hand-coded LL(1+), recursive descent, which limits certain kinds of syntax. Shouldn’t be a problem in practice. The grammar is quite small.

Leave a Comment

Filed under Uncategorised

Image relations

TTM and its companion book DTATRM talk about an IMAGE RELATION function, that joins two relations, embedding matching tuples from the right as a relation-valued attribute of the left.

Here is a piece of code that creates an RVA. The relation exam_mark is partitioned across the several courses.

cer := course [{ CourseId, ExamResult := {{ * }} joinr exam_mark}]

CourseId   | ExamResult
----------------------------------
C1         | StudentId  | Mark
           | ---------------------
           | S1         |       85
           | S2         |       49
           | S4         |       93
C2         | StudentId  | Mark
           | ---------------------
           | S1         |       49
C3         | StudentId  | Mark
           | ---------------------
           | S3         |       66
C4         | StudentId  | Mark
           | ---------------------

Here is a piece of code that does the job of putting the tuples back together again.

cer [{ fold(union,ExamResult) }]

StudentId  | Mark
---------------------
S1         |       85
S2         |       49
S4         |       93
S1         |       49
S3         |       66

Note that this relies on an anonymous attribute, which is ‘lifted’ out as a single value.

Leave a Comment

Filed under Language

99 bottles of Andl beer!

In response to a challenge, I decided to actual solve the problem. Here it is. The lyrics are here: http://www.99-bottles-of-beer.net/lyrics.html

ten := {{ n:=0 },{ n:=1 },{ n:=2 },{ n:=3 },{ n:=4 },{ n:=5 },{ n:=6 },{ n:=7 },{ n:=8 },{ n:=9 }}
hundred := (ten join ten[{nn:=n}]) [ {neg := -10*nn-n,nnn := 10*nn+n}] [nnn>0]
line1 := hundred [{ neg, text := nnn || " bottle" || if(nnn=1,"","s") || " of beer on the wall, " || 
         nnn || " bottle" || if(nnn=1,"","s") || " of beer."}]
line2 := hundred [{ neg:=neg+0.5, text := "Take one down and pass it around, " || (nnn-1) || " bottle" ||
         if(nnn=2,"","s") || " of beer on the wall."}]
line3 := "No more bottles of beer on the wall, no more bottles of beer."
line4 := "Go to the store and buy some more, 99 bottles of beer on the wall."
(line1 union line2) [$] [{text}] union {{text:=line3},{text:=line4}}

The first two lines just generate the sequence. Later there will be a better way to do that. The 4 lines of text are dictated by the song lyrics. Most of the program is fiddly details to precisely match the song lyrics as published, and get the lines in the right order. The end result is a relation containing the song lyrics in the correct order, which is then simply printed.

I found this quite a fascinating exercise. I had to implement IF(,,) but I think the only other control structure needed is user-defined recursive functions. The result is a programming paradigm quite unlike any that I’m familiar with, and surprisingly powerful. And weird.

Leave a Comment

Filed under Code sample, Language