BASIC Developer & Support Resources > Translators


(1/15) > >>


--- Quote ---Nimrod is a statically typed, imperative programming language that tries to give the programmer ultimate power without compromises on runtime efficiency. This means it focuses on compile-time mechanisms in all their various forms.

Nimrod borrows features from lots of languages. Major influences are Pascal/Delphi, Modula 3, Ada, C++, Lisp, Python, Oberon.

Nimrod also has many unique and novel features that set it apart from the crowd:

[*] An effect system in addition to a type system.
[*] Part of the effect system is "exception tracking" which is Java's checked exceptions done right.
[*] Overloading based on ASTs in addition to overloading based on types.
[*] Term rewriting macros for user definable optimizations that can be based on side effect and alias analysis.
[*] And lots more ...

Nimrod is a language that scales: You can use it for a whole software stack; both low level and high level code are right at home in Nimrod.

What is Nimrod?

Nimrod is a general purpose, statically-typed, imperative programming language that supports procedural, object-oriented, functional and generic programming styles while remaining simple and efficient.  Nimrod runs on Windows, Linux, BSD and MacOS X.

Nimrod Design

The Nimrod compiler generates optimized C code and defers compilation to a wide range of external compilers.  Nimrod supports objects with inheritance, overloading, polymorphism and multiple dispatch.  Nimrod treats procedures as first-class entities, meaning it can also be used for functional programming.  Nimrod also supports metaprogramming by a combination of generics, templates, macros, conditional compilation with compile-time function execution, and user-defined operators.

Nimrod has high-level data types, including strings, arrays, sequences, sets, tuples, enumerations, etc.  Most objects created on the heap are managed with garbage collection. Nimrod also supports a module mechanism to create independent libraries.  The Nimrod standard library has I/O and OS operations, string utilities, Unicode support, regular expressions, and various parsers such as command line options, XML, CSV, and SQL.

Nimrod History

Nimrod was created in 2004 by Andreas Rumpf.  It was originally coded in Object Pascal (FreePascal) and Python.  However, the first version that bootstrapped (was able to compile itself) was released in 2008.

--- End quote ---

Kent from the OxygenBasic forum (and now an advocate here) found a really nice BASIC like front end language to C. I think the author did an outstanding job and it seems to have a loyal following. The language is a conglomeration of many existing languages including SB. It has a strong Python and Pascal flavour to it but still has many of the BASIC constructs and high level language features. (garbage collection, OOP, truples, sequences and bit shifting if needed) The best part is it has bindings to most of the main stream libraries and embeddable scripting engines. A C header file converter is included if need to create your own custom binding.
Nimrod has an IDE (Aporia) that is written in Nimrod. It uses Gtk and the gtksourceview widget for the editor. The IDE is also a good resource to get a feel how Nimrod as a language flows.

Nimrod Project Site

Nimrod Manual

Nimrod is also a supported language for the site. (see attached)


--- Code: ---type
    TPerson = tuple [name: string, age:int]

proc result(): TPerson = ("John",60)

var r = result()
echo(r)             # default stringification
echo (       # access by field name
var (name,age) = r  # tuple unpacking
echo (name,"|",age)

--- End code ---

jrs@laptop:~/nimrod/examples$ nimrod c -d:release tuple.nim
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: tuple [Processing]
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o examples/nimcache/tuple.o examples/nimcache/tuple.c
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o examples/nimcache/system.o examples/nimcache/system.c
gcc   -o /home/jrs/nimrod/examples/tuple  examples/nimcache/system.o examples/nimcache/tuple.o  -ldl
Hint: operation successful (7450 lines compiled; 3.350 sec total; 8.870MB) [SuccessX]
jrs@laptop:~/nimrod/examples$ ./tuple
(name: John, age: 60)

A Nimrod version of the Linux head console command.

--- Code: ---import parseopt
from strutils import parseInt
from os import existsFile

const usage = """
head [flags] filename
  -n: number of lines (default 10)
  -h,--help: this help
  -v,--version: version

proc showUsage(msg: string) =
  if msg != nil: echo("head: ",msg)
proc head(file: string, n: int) =
  if not existsFile(file):  quit("file " & file & " does not exist")
    f = open(file)
    i = 0
  for line in f.lines:
    i += 1
    if i == n: break
proc parseCommands() =
    files: seq[string]
    n = 10
  for kind, key, val in getopt():
    case kind
    of cmdArgument:
    of cmdLongOption, cmdShortOption:
      case key
      of "help", "h": showUsage(nil)
      of "n":
        n = parseInt(val)
      of "version", "v":
    of cmdEnd: assert(false) # cannot happen
  if len(files) == 0:
    # no filename has been given, so we show the help:
    showUsage("please supply filename")
  if len(files) == 1:
    for f in files:
      echo("----- ",f)

--- End code ---

jrs@laptop:~/nimrod/examples$ nimrod c -d:release nhead.nim
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: nhead [Processing]
Hint: parseopt [Processing]
Hint: os [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: times [Processing]
Hint: posix [Processing]
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o examples/nimcache/nhead.o examples/nimcache/nhead.c
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o examples/nimcache/parseopt.o examples/nimcache/parseopt.c
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o examples/nimcache/os.o examples/nimcache/os.c
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o examples/nimcache/strutils.o examples/nimcache/strutils.c
gcc   -o /home/jrs/nimrod/examples/nhead  examples/nimcache/posix.o examples/nimcache/times.o examples/nimcache/parseutils.o examples/nimcache/strutils.o examples/nimcache/os.o examples/nimcache/parseopt.o examples/nimcache/system.o examples/nimcache/nhead.o  -ldl
Hint: operation successful (14375 lines compiled; 0.569 sec total; 15.158MB) [SuccessX]
jrs@laptop:~/nimrod/examples$ ./nhead -n=5 nhead.nim
import parseopt
from strutils import parseInt
from os import existsFile

const usage = """
jrs@laptop:~/nimrod/examples$ ls -l nhead
-rwxrwxr-x 1 jrs jrs 67253 Sep 21 23:34 nhead


--- Quote ---Here we are making objects which are references (by default they are value types, like tuples, unlike java), initialized with the standard procedure new. Note the Pascal-like special variable result in procedures!

As expected, you may pass Germans to sayit, because a German is a person, but greeting has to be declared as a method for this to work; if it were a proc, we would get a warning about the second greeting being unused, and Germans are then addressed in English.

The cool thing about multi-methods is that they restore symmetry; a traditional polymorphic call is only polymorphic in a. This makes sense in a language where dot method notation is just sugar for procedure calls where the first argument matches the type.

--- End quote ---

--- Code: ---type
    TPerson = object of TObject
        name: string
        age: int

proc setPerson(p: ref TPerson, name: string, age:int) = = name
    p.age = age

proc newPerson(name: string, age:int): ref TPerson =

method greeting(p: ref TPerson):string = "Hello " & & ", age " & $p.age

    TGerman = object of TPerson

proc newGerman(name: string, age:int): ref TGerman =

method greeting(p: ref TGerman):string = "Hallo " & & ", " & $p.age & " Jahre alt"

var john = newPerson("John",60)
var rene = newGerman("Rene",43)

proc sayit(p: ref TPerson) = echo p.greeting


--- End code ---

jrs@laptop:~/nimrod/examples$ nimrod c -d:release class.nim
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: class [Processing]
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o examples/nimcache/class.o examples/nimcache/class.c
gcc   -o /home/jrs/nimrod/examples/class  examples/nimcache/system.o examples/nimcache/class.o  -ldl
Hint: operation successful (7468 lines compiled; 0.297 sec total; 8.870MB) [SuccessX]
jrs@laptop:~/nimrod/examples$ ./class
Hello John, age 60
Hallo Rene, 43 Jahre alt

Thanks John, I got no where with Nimrod. Your encouraging work and wonderful detailed posts of your progress are really motivating. I hope to catch up soon and contribute also.

I am glad you got Aporia working, as having a nice IDE is something I have been spoiled by in recent years with Code::Blocks, Lazarus and Visual Studio.

Do you do all of your development in Ubuntu and use Wine for Windows testing John?


[0] Message Index

[#] Next page

Go to full version