F.E.L.T.

Functionally Equivalent Language Translation

FELT Syntax

Irrespective of which back-end coder you choose to render your final output, the syntax of your FELT application is always the same which makes it easy to learn and easier to eventually forget all about the syntax of the target language altogether. Eventually you will know only FELT and then world domination is only a semi-colon away. Mwah hah hah etc. Except that FELT doesn't use semi-colons other than as the start-of-line comments.

S-Express yourself!

With s-expressions, what else. If you want a rather detailed description of what an "s-expression" is then you could a lot worse than read the Wikipedia page on s-expressions. FELT uses s-expressions to allow you to express your algorithmic intent in the simplest form possible. Rather than invent yet another new syntax for you to learn, the chances are that you have at some point already seen Lisp programs around the 'net and so you will (hopefully) more than likely recognise the form when you see it. And if you did "CS" in college / university then I am guessing you may have done a term on "AI" with Lisp. Sadly it is still perceived as an "AI" language, and also (rather foolishly) still perceived as slow and hard-to-learn. Rubbish! On both counts.

One Syntax Rule

Without sounding too "Lord of the Rings", FELT has one rule to bind them all. That is to say, there is exactly one form to learn to be able to code anything with FELT. That's not to say that there aren't different forms to learn for doing various things like making decisions, iterating loops etc. but the uniformity of syntax means that your brain has only to focus on the instruction to hand rather than what shape it is. For example, in PHP there are different syntactical forms for if, for, foreach, switch etc.

The essence of FELT instruction formatting is this:

;; It doesn't get simpler than this baby!
(INSTRUCTION ARG1 ARG2 ARG3 ... ARGN)
;; Calling functions inside a function.
(FOO (BAR 10) (BAZ (+ 10 32)) "Hello World")

There are no exceptions to this rule. Anywhere. Ever. That's it. You have now ingested all the knowledge about the actual form of FELT code. Feels good doesn't it!

Please read the "Writing FELT Code" for complete and detailed instructions on actually coding your next killer application (kipper allocation?).

Line Continuations

One of the banes of PHP and a lot of other languages is "long lines"; I realise that you personally try never to write lines of code longer than about eighty characters in length, despite having a 28-inch monitor. However, it may be the case that the previous cowboy developer had some kind of allergic reaction to using the RETURN key or the SPACE key and has left a festering purulent legacy of code that at times resembles what would happen if you stuffed a pound of C4 explosives into a folder full of PDF files.

Taking a leaf from Haskell and 'C' then, FELT provides a "line continuation" character that when placed at the end of a source line, ignores all further input until another of those characters is received in the input stream. That doesn't sound too hard but it has some interesting side effects as we will see!

Basic line continuation example

Let's say that you wanted to print out a long string but you want to break it over a couple of lines for clarity, here is how you would do it in FELT:

(defvar long-string "\
\This is a long string that \
\I wanted over \
\a couple of lines!")

And the PHP code for this would be like so:

$long_string = "This is a long string that I wanted over a couple of lines!";

Extended example; it this useful?

As you can see, everything after the last back-slash character is ignored until the next one is seen. The detection of the second character then starts feeding subsequent characters into FELT again, discarding the second one course!

This means that you could in theory make "margin notes" in your code... I am not suggesting that this is something you should do but merely something that can be done. You can use this feature to make special notes against code if you want to or just leave a shopping list:

(defvar long-string "\

  TONIGHT:          \This is a long string that \

    - order pizza    \I wanted over \
    - make coffee!    \a couple of lines!")

And lo and behold, the generated PHP and JavaScript output from the above:

$long_string = "This is a long string that I wanted over a couple of lines!";
var long_string = "This is a long string that I wanted over a couple of lines!";

So, that's pretty much all there is to say about line continuation characters. It means that you can use them to, for example, split SQL over a couple of lines and, unlike PHP, not have spurious amounts of white-space being sent to the the My-SQL server just because you laid the code out a certain way.

Comments

The choice of characters to use for commenting was initially inspired by Haskell, I had the curly braces as multiple line comments and a double hyphen (like SQL) for a single line comment but as FELT grew it became necessary to commandeer all available brackets for various language features.

The final choice is reasonably straight forward and should not really come as a great surprise other than the single line comment. To a Lisp hacker of course it will be perfectly normal.

Single line

Single line comments are started with ;, the semi-colon character. Everything after the first character is detected is ignored up until the end of the current line. Depending on what platform you are on this may equate to "carriage return" or "carriage return + line feed". However, you shouldn't need to worry about that as PHP being the implementation language "knows" when it has reached the end of the current line.

; I am a comment
;; So am I
;;; Me too
;; Hey, we just made
; a right-arrow shape! ;)

Comments are swallowed by FELT and not passed through to the generated code. This MAY change in the future but for now the back-end coders will not contain any of the comments you may enter into your FELT source text.

Multiple line

To comment out a block of code over many lines you use the opening sequence /*, forward-slash-asterisk, and to close it again use */, asterisk-forward-slash. This is the same as used for PHP, C and many many other languages and is probably one that you are used to seeing and using already.

Nested Comments

You can't! In other words.... like the 'C' language, once you open a multiline comment block with /*, if you use that sequence again it will be ignored as many times as it occurs BUT when the very next */ is detected, FELT will drop out of "comment mode" and start interpreting the still- active comment as code and all hell will probably result. Here's a short example and that's all that's to be said on the matter...

/* This is a comment
   /* Def. causing trouble now! */
*/

And guess what, the PHP is junk but don't say nobody told you not to try and nest comments...

$_star__rs_;

Huh? Explanation: the opening comment started to silently junk stuff until the first */ at which point FELT switches back to code mode, and it has dutifully turned the second close-comment sequence into a variable. Computers can be really dumb at times and I guess this is one of them; after all they only do what you tell them to do.

Strings

FELT doesn't really hold too many surprises, if any, when it comes to entering strings. Using the line continuation character means that very long strings can be neatly laid out of required, albeit at the "loss" of interpretation of the implicit line-feed characters into the final string.

Double-Quote Strings

Pretty much anything that you can enter at the keyboard can go into a string, the only exception is of course the double-quote character! If you want to enter that then you must precede it with a backslash. Exactly how the string is treated at "run-time" depends of course on what language you choose to execute your code with.

(emit "\nJoe said, \"\nFELT\n\t\tis\n\t\t\tcool!\"\n")

The above example will produce PHP like this:

echo "\nJoe said, \"\nFELT\n\t\tis\n\t\t\tcool!\"\n";

And Node.js/JavaScript like this:

console.log("\nJoe said, \"\nFELT\n\t\tis\n\t\t\tcool!\"\n");

Single-Quote Strings

Not much to say really except that the only character not allowed in a single quoted string is... go on, have a guess... the single quote character. Damn you guys are good!

And how do we put a single quote in a string surrounded by single quotes? Simple, just prefix it with with a backslash character the same as you would do for a double quote in a double-quote encased string.

Keywords

A "keyword" is something FELT borrows from Lisp-world. It can make for very readable code and also helps to differentiate the use of a string as a "property key" or as data when using association lists. See ALIST.

A keyword can contain any character that is not in the set [](){} and MUST start with a : (colon) character. Exactly how that is rendered is once again down to the selected back-end coder but for the PHP and JavaScript coders it will be translated into a single quoted string. For the CSS coder is will come out as a the same thing but with the colon moved to the other end!

;; declare a set of properties
(defun some-stuff ()
  (return {
    :name     "Eric"
    :likes    "FELT, coffee and playing the Dij"
    :dislikes "Sloppy coders"
  }))

This renders out in PHP as this:

function some_stuff()
    {return array('name' => "Eric", 'likes' => "FELT, coffee and playing the Dij", 'dislikes' => "Sloppy coders");}

And like this in JavaScript:

var some_stuff = {'name' : "Eric", 'likes' : "FELT, coffee and playing the Dij", 'dislikes' : "Sloppy coders"};

And for completeness the CSS coder generates this:

You can see that apart from the fact that "name", "likes" and "dislikes" are not valid CSS statements, that the end-result is something that would work as CSS if you changed those to something like "color", "font-size" and "background-color" for example. Please read (the CSS Coding Guidelines)[/ref/codecss] for more on using FELT for CSS.

Not Strings

What strings? No... not strings! FELT is not a language per se as it doesn't actually produce anything that "runs" in the conventional sense. Therefore it doesn't really have data types, all it has are tokens and not-tokens. I love the work of the sculptor Henry Moore and one of his many erudite quotes kind of sums up what FELT is all about at this juncture:

"To know one thing, you must know the opposite." - Henry Moore

So, having described strings that FELT will recognise, being wrapped in single quotes, double quotes or being a single unbroken sequence of characters preceded by a colon, everything else is deemed to be a not-string, as opposed to a number or this or that.

FELT scans your code into a small set of things: brackets that open, brackets that close, strings and everything else!

bear that in mind and you will be able to maintain the "relaxed attitude" to FELT coding that is required. Coding FELT will push your mind into thinking about how to write portable code from the outset. Like most things in life you get out what you put in and the harder things are most often the most rewarding when you "grok" them!

Operators

FELT supports the usual bunch of operators.

= (ASSIGN)

The assign instruction is the class imperative destructive assignment, the right-hand side being copied into the left-hand side. Some languages allow you to bring variables into scope but it is safer and more portable to use DEFVAR for this, refer to that page for more information.

== (EQUALITY)

FELT loosely translates this as meaning "is the left hand side 'the same' as the right hand side". Which, if you think about it is all it can do as the exact meaning is down to the chosen back-end language. Fortunately though most languages use the "==" sequence to mean the same thing.

NOT

To formally test for the negation condition you have to use the NOT instruction. In PHP this is equivalent to the ! (exclamation), as it is also for JavaScript and a lot of other languages out there.

Next...

Having read and understood the FELT syntax, and realised just how simple it is, you are now ready to read the page about how to code in FELT for fun and profit.