Nimrod language

bearophile bearophileHUGS at lycos.com
Sat Jan 1 10:00:15 PST 2011


Through Reddit I have found a short discussion about the Nimrod language, it's a garbage collected statically typed language fit for low level coding too, despite it looks a lot like Python (with a bit of Pascal semantics added), it has generics too, templates, and macros, its compiler is written in Nimrod itself, and it compiles to C:
http://www.reddit.com/r/programming/comments/eub63/nimrod_programming_language/

I've seen that there's an older link to Nimrod in D newsgroups:
http://www.digitalmars.com/d/archives/digitalmars/D/Complete_off_topic_Nimrod_language_107212.html

The Nimrod site:
http://force7.de/nimrod/index.html

Two pages of tutorials (there is a manual too, elsewhere):
http://force7.de/nimrod/tut1.html
http://force7.de/nimrod/tut2.html
About AST macros:
http://force7.de/nimrod/macros.html

Here are some quotations and notes about the tutorials (version 0.8.10), the Reddit thread (and the manual), I show some Nimrod features:

-------------------

>Case is insignificant in Nimrod and even underscores are ignored: This_is_an_identifier and ThisIsAnIdentifier are the same identifier. This feature enables you to use other people's code without bothering about a naming convention that conflicts with yours. It also frees you from remembering the exact spelling of an identifier (was it parseURL or parseUrl or parse_URL?).<

So the "_" is not usable, and if you search for names in the code you need to set it to ignore underscores.

-------------------

>Comments are tokens; they are only allowed at certain places in the input file as they belong to the syntax tree! This feature enables perfect source-to-source transformations (such as pretty-printing) and superior documentation generators.<

-------------------

>Hexadecimal literals are prefixed with 0x, binary literals with 0b and octal literals with 0o. A leading zero alone does not produce an octal.<

-------------------

>To call a procedure that returns a value just for its side effects and ignoring its return value, a discard statement has to be used. Nimrod does not allow to silently throw away a return value:<

discard factorial(10)

-------------------

It has iterators with a syntax similar to Python:

iterator countup(a, b: int): int =
  var res = a
  while res <= b:
    yield res
    inc(res)

-------------------

There's a way to specify integer literals of the desired size, signed bytes too:

var
  x = 0     # x is of type ``int``
  y = 0'i8  # y is of type ``int8``
  z = 0'i64 # z is of type ``int64``

-------------------

>Automatic type conversion in expressions with different kinds of floating point types is performed: the smaller type is converted to the larger. Integer types are not converted to floating point types automatically and vice versa. The toInt and toFloat procs can be used for these conversions.<

-------------------

It has integral subranges (ranged types of Pascal, Ada):

type
  TSubrange = range[0..5]

-------------------

One of the compilation options is to turn on "hints" (there are warnings and errors too):

hints	on|off 	Turns the hint messages of the compiler on or off.

-------------------

Overall it looks like a quite nice language. I have not tried to program with it yet.

Bye,
bearophile


More information about the Digitalmars-d mailing list