TTM and the Nim programming language
Quote from Rene Hartmann on November 17, 2018, 8:54 pmI have written a Nim API for DuroDBMS.
Nim is a relatively new language which combines a Python-like syntax with semantics similar to the Pascal family of languages (Modula-2, Ada...)
Why Nim? Nim provides powerful metaprogramming facilities. This allows extending the language by a relational algebra similar to Tutorial D in a type-safe way.
For example, the following Tutorial D expression:
((t1 JOIN t2) WHERE a = 1) { b }
is equivalent to the following expression in Nim:
V(t1).join(V(t2)).where(V(a) $= 1){ b }
Some TTM functionality is still missing, such as WRAP/UNWRAP, GROUP/UNGROUP and multiple assignment, but most of the relational algebra and single INSERT/UPDATE/DELETE is already there.
Project page: https://github.com/rehartmann/nidurodb
I have written a Nim API for DuroDBMS.
Nim is a relatively new language which combines a Python-like syntax with semantics similar to the Pascal family of languages (Modula-2, Ada...)
Why Nim? Nim provides powerful metaprogramming facilities. This allows extending the language by a relational algebra similar to Tutorial D in a type-safe way.
For example, the following Tutorial D expression:
((t1 JOIN t2) WHERE a = 1) { b }
is equivalent to the following expression in Nim:
V(t1).join(V(t2)).where(V(a) $= 1){ b }
Some TTM functionality is still missing, such as WRAP/UNWRAP, GROUP/UNGROUP and multiple assignment, but most of the relational algebra and single INSERT/UPDATE/DELETE is already there.
Project page: https://github.com/rehartmann/nidurodb
Quote from dandl on November 18, 2018, 10:23 amYes, I've run across Nim but not yet had a reason to use it. The metaprogramming aspect caught my eye.
It's very hard to implement the TTM type system in any established computer language. There are no major languages that I know of which can provide all of:
- value semantics (rather than reference semantics)
- strong compile time type checking (not dynamic typing)
- structures (records) with order-insensitive members.
The best I could do was to propose a starting point of Java or C# and a language extension implemented as a modified compiler. My Andl.Net project shows how that might look.
So how did you go? Can Nim do all these things?
Yes, I've run across Nim but not yet had a reason to use it. The metaprogramming aspect caught my eye.
It's very hard to implement the TTM type system in any established computer language. There are no major languages that I know of which can provide all of:
- value semantics (rather than reference semantics)
- strong compile time type checking (not dynamic typing)
- structures (records) with order-insensitive members.
The best I could do was to propose a starting point of Java or C# and a language extension implemented as a modified compiler. My Andl.Net project shows how that might look.
So how did you go? Can Nim do all these things?
Quote from Rene Hartmann on November 18, 2018, 12:25 pmI must admit that the relational algebra expressions are not truly type safe (yet - maybe I will find a way to achieve that, but it's hard as Nim wasn't designed for that kind of thing).
Using Nim macros and generics currently two things are achieved: A TD-like syntax, and copying query results into statically typed Nim sequences and tuples, without having to resort to run-time type information (as you would have to in e.g. Java).
But if the target type does not match the relation type, that's a run-time error.
Nim supports value semantics, but unfortunately its tuples are ordered.
I must admit that the relational algebra expressions are not truly type safe (yet - maybe I will find a way to achieve that, but it's hard as Nim wasn't designed for that kind of thing).
Using Nim macros and generics currently two things are achieved: A TD-like syntax, and copying query results into statically typed Nim sequences and tuples, without having to resort to run-time type information (as you would have to in e.g. Java).
But if the target type does not match the relation type, that's a run-time error.
Nim supports value semantics, but unfortunately its tuples are ordered.
Quote from Darren Duncan on November 18, 2018, 8:02 pmQuote from dandl on November 18, 2018, 10:23 amYes, I've run across Nim but not yet had a reason to use it. The metaprogramming aspect caught my eye.
It's very hard to implement the TTM type system in any established computer language. There are no major languages that I know of which can provide all of:
- value semantics (rather than reference semantics)
- strong compile time type checking (not dynamic typing)
- structures (records) with order-insensitive members.
The best I could do was to propose a starting point of Java or C# and a language extension implemented as a modified compiler. My Andl.Net project shows how that might look.
So how did you go? Can Nim do all these things?
You should check out Perl 6, thoroughly modern, meta programming is one of its most fundamental features, and it should be able to act as what you wanted.
Quote from dandl on November 18, 2018, 10:23 amYes, I've run across Nim but not yet had a reason to use it. The metaprogramming aspect caught my eye.
It's very hard to implement the TTM type system in any established computer language. There are no major languages that I know of which can provide all of:
- value semantics (rather than reference semantics)
- strong compile time type checking (not dynamic typing)
- structures (records) with order-insensitive members.
The best I could do was to propose a starting point of Java or C# and a language extension implemented as a modified compiler. My Andl.Net project shows how that might look.
So how did you go? Can Nim do all these things?
You should check out Perl 6, thoroughly modern, meta programming is one of its most fundamental features, and it should be able to act as what you wanted.
Quote from dandl on November 18, 2018, 11:51 pmPerl 6 is not an easy beast to get to grips with. There is so much history, so much mixture of old and new, so much strange terminology. Mu, anyone?
But yes, it seems Perl 6 has static typing (as well as dynamic); and yes, it's probably possible to define objects with value semantics. But I can't easily confirm that it can handle order-insensitive structures. I would have to drink far too much of the Perl 6 Kool-Aid to figure that out.
Perl 6 is not an easy beast to get to grips with. There is so much history, so much mixture of old and new, so much strange terminology. Mu, anyone?
But yes, it seems Perl 6 has static typing (as well as dynamic); and yes, it's probably possible to define objects with value semantics. But I can't easily confirm that it can handle order-insensitive structures. I would have to drink far too much of the Perl 6 Kool-Aid to figure that out.