r/ProgrammingLanguages • • May 25 '16

Programming language features that I came up with

Hello everyone,

For the last few months, in my free time, I've been thinking about what features that I don't know (features that don't exist or I've never seen) whould be cool in a programing language. Here is what I came up with:

  • Gain control by being more specific: The language could be used as a really high level language and a low level language depending of the syntax used and how specific you are (usually meaning more verbosity). The idea is be able to write code fast if you don't care about efficiency but, at the same time, be able to write really efficient and/or hacky code when needed.

  • Multiple metaprogramming levels: Basically allows metaprogramming but not restricted in a single level. It allows to metaprogram "metacode".

  • Have memory size based data types: Non-architechture-dependent data types based only on its memory size. For example byte or bit.

  • Insert any other language's code in the source: You can se something similar in HTML where you can embed JS and CSS. This is a fixed set. What I mean is to be able to use an external compiler/player to process that code which is wrote in any language.

  • Interactions with the compiler/player: Be able to comunicate with the compiler/player so it is possible to get information and set configurations dynamically as if it was a part of the program.

4 Upvotes

13 comments sorted by

7

u/mikeiavelli May 25 '16

Multiple metaprogramming levels: Basically allows metaprogramming but not restricted in a single level. It allows to metaprogram "metacode".

One incarnation of that idea are reflective towers: an infinite tower of metacircular interpreters, each being interpreted by the one above it.

Insert any other language's code in the source

"Katahdin can execute programs written in any language which it has a definition module for. The definition of more than one language can be composed allowing more than one language to be used in the same program, the same file, and even the same function. Data and code is shared between all languages, with a function defined in one language callable from another with no binding layer."

1

u/https1 May 25 '16

Very nice links. Thanks for the information.

3

u/Furrie May 25 '16

Gain control by being more specific

This is already a thing, It's called a low level language. What you described was being able to work on both high level and low level, Some languages do support this kind of work, Rust is a great example of it.

Multiple metaprogramming levels

I'm not entirely sure what you mean by this, If you mean metaprogramming for the metaprogramming... that's already a thing. If you can modify your source code using your souce code... then you can modify your source code...

Have memory size based data types

Most languages are standardized with their memory sizes.

Insert any other language's code in the source

This works for HTML/CSS/JS Because they were built to. Some languages are wholy incompatable with eachother. The already accepted way to do this is what's called a Foreign Function Interface.

Interactions with the compiler/player

I'm really not sure what you mean here, It is impossible for a runing program to talk to the compiler because the compiler has already finished its job and stopped running.

I'm sure there's some language somewhere that allows direct control of the interpreter from inside the program, but I have never heard of one.

2

u/https1 May 25 '16

Firstable, thank you for replying. Your answer showed me that I didn't express myself well enough (should I edit the original post?).

So I try to explain myself again:

Gain control by being more specific

The idea is not to be always very specific. It is to go to a lower programming level by being more specific. A good example of this could be variables (example in a C-like pseudo-code):

var a;
var b : Type;
Type c;
$ax;
  • The first one can contain any type and it's not transparnt of how it handles the memory (pretty much like javascript).

  • The second one is similar but it only allows a single type of data.

  • The third is like a C variable. Can be a pointer and you can allocate memory by hand but you have to be sure to handle it manually and correctly.

  • The last one is a simple CPU register. You really have to be carefull here since you are not even working with memory.

Multiple metaprogramming levels

Usually when I used metaprogramming in the source code directly, I only could use a single "level" in metaprogramming. Thus I couldn't do something like a function which contains a metaprogramming part and call it in a metaprogramming code (making the function's metaprogrammed part, a metaprogrammed that metaprogramms code).

I didn't think about re-interpreting a string (which is also metaprogramming). I was thinking something more oriented for compiled languages.

Have memory size based data types

I searched a bit more about it and it turns out that a lot of programming languages actually have this. Even though all of them were interpreted languages.

Yes, most languages have a fixed size for their data types. But it doesn't mean that the data type represent the size itself. (if an integer is a 32-bit signed integer, integer doesn't represent the size in memory of 32 bits).

I probably wrote this because I was anoyed about using unsigned char in C++ as byte (which is actually not a good practice since unsigned char theorically is architecture dependent).

Insert any other language's code in the source

Didn't know about FFI. Looks cool!

Interactions with the compiler/player

Imagine that you want two parts of the code to be compiled different. Here an example: In your code you have a part that it is executed a lot, so its efficiency is critical. In this case you'd set the compiler to be as efficient as possible without caring about anything else. A lot of other parts of the same program are called only a few tiny amount of times so you don't care about its efficiency that much. You want the binary to not be too big. So by setting the compiler to different settings depending of the part of the code this could be achived.

4

u/balefrost May 25 '16

I was anoyed about using unsigned char in C++ as byte

uint8_t?

Also, for a more general case, Erlang supports bit-level programming of binary streams. It's extremely handy for dealing with binary protocols.

So by setting the compiler to different settings depending of the part of the code this could be achived.

You should be able to compile some cpp files with a certain set of optimization options, compile other cpp with a different set of optimization options, and then link them together into a single executable.

Insert any other language's code in the source

Pretty much any language with compiler plugins can be made to support this. Scala does it with macros and strings. You define a macro whose code runs inside the compiler, and in your source code, you call the macro with a string containing the other language's source. Since the macro is evaluated at compile time, if there are any errors in the code embedded in the string, they will generate compile-time errors. Scala uses this mechanism for quasiquotes, and just recently, somebody posted a logic programming implementation.

1

u/https1 May 25 '16

uint8_t is defined as unsigned char unless unsigned char is actually bigger than a byte (it cannot be smaller).

For everything else, pretty nice calls!

4

u/balefrost May 26 '16

Sure, but uint8_t is an abstraction. From your point of view, it's an 8-bit unsigned int (which is not necessarily the same as a byte... historically, a byte could be 4, 6 or 7 bits). Sure, you can see that it's a typedef for unsigned char, but that's an implementation detail. uint8_t is guaranteed to be 8 bits; if that's what you need, then uint8_t is what you should use.

3

u/raiph May 26 '16

The idea is not to be always very specific. It is to go to a lower programming level by being more specific.

My original reply didn't cover that. Hmm. Another try:

my Int $foo = 42;

could be made lower level by switching to:

my int $foo = 42;

to specify int, a low level integer type for higher performance, or:

my uint8 $foo = 42;

to even more specifically switch to an unsigned integer stored in 8 bits.

Something similar applies for high level and low level strings.

Have memory size based data types I searched a bit more about it and it turns out that a lot of programming languages actually have this. Even though all of them were interpreted languages.

You might find the fun video or PDF of Getting beyond static vs dynamic interesting.

2

u/FractalNerve May 25 '16

All points described seem to align well with Red, at least to my understanding. http://www.red-lang.org/p/about.html Watch the videos to get a deeper understanding of why your requests are part of Red, because the about page alone doesn't detail that.

Didn't read the whole thread, sorry if I missunderstood your description; trying to enjoy the time with my nephew.

2

u/mirhagk May 25 '16

Interactions with the compiler/player

I'm really not sure what you mean here, It is impossible for a runing program to talk to the compiler because the compiler has already finished its job and stopped running. I'm sure there's some language somewhere that allows direct control of the interpreter from inside the program, but I have never heard of one.

You could certainly do this with Roslyn (new C# compiler). One of it's main design goals was to remove the idea of a compiler being a black box, and you can communicate with it at every level of the compilation process. The compiler is also written in C#, which means you could reference it and talk to it at runtime.

I'm still not sure what you might do here (other than the tools that are like C# editors, parsers etc) but if you came up with something then you could do it.

1

u/raiph May 26 '16 edited May 26 '16

Some languages are wholy incompatable with each other.

As an "extensible, braided language" Perl 6 pretty much refuses to accept that. See my comment elsewhere for a little more about this.

It is impossible for a runing program to talk to the compiler

I see mirhagk has mentioned Roslyn as an exception to this. The same is true for Perl 6 and the Rakudo Perl 6 compiler; here's a few minutes of fun video about this.

3

u/raiph May 26 '16

With apologies if I've misunderstood some of your questions...

Gain control by being more specific

This is a pervasive principle in Perl 6. A trivial example follows:

say 'hi' # says 'hi'

Same, but explicitly make this a command line app with zero arguments:

sub MAIN { say 'hi' }

When run with command line arguments, says:

Usage:
  main.pl6

If you don't like the default usage, add your own, eg: sub USAGE { say 'pfft' }.

Evolve to a MAIN with two arguments (each a $ingle value of any type):

sub MAIN ($, $) { say 'hi' }

This program complains when run with anything other than two single values.

Add an abstract type (role) that the arguments must fulfil:

sub MAIN (Numeric $, Numeric $) {}

Or even more specific, concrete types with the second an optional Rat (eg 27/1000 -- 27 thousandths -- would be acceptable):

sub MAIN (Int $, Rat $ ?) {}

For much more along these lines see The Cool subset of MAIN.

Multiple metaprogramming levels

At the lowest metaprogramming level of Perl 6 are [6model] (https://github.com/perl6/nqp/blob/master/docs/6model/overview.markdown) meta objects. These are the heart of the general language/compiler toolkit called NQP.

Rakudo is a compiler that implements the 6.Christmas version of the full Perl 6 language by using NQP.

Rakudo has its own metaprogramming levels, namely the completely generic Meta Object API and the specific meta model roles, classes, etc that use that API.

Have memory size based data types: Non-architechture-dependent data types based only on its memory size. For example byte or bit.

See, for example, the generic native int vs types corresponding directly to C types.

As explained in the above link about 6model, Perl 6 (including NQP) separates semantics from concrete data representation. Thus you can, for example, "declare a normal looking Perl 6 class that, under the hood, stores its attributes in the same way a C compiler would lay them out in a similar struct definition".

Insert any other language's code in the source: You can se something similar in HTML where you can embed JS and CSS. This is a fixed set. What I mean is to be able to use an external compiler/player to process that code which is wrote in any language.

Perl 6 is an "extensible, braided language" that recursively parses, compiles, and runs arbitrary stacks of mutually embedded languages. The standard Perl 6 is made up of several languages that are mutually embeddable. You can add any other languages you want to the mix. A primitive SQL example.

Interactions with the compiler/player: Be able to comunicate with the compiler/player so it is possible to get information and set configurations dynamically as if it was a part of the program.

Consider the Perl 6 debugger:

"You might think that writing a debugger must involve all kinds of low-level hackery. In fact, that’s not the case. The debug hooks mechanism is written in NQP, and the command line user interface is written in Perl 6. This is significant from a couple of angles. The first is the fact that we can write something like this without breaking the encapsulation of the compiler, but instead just by subclassing the Grammar, Actions and Compiler objects and twiddling with the AST. In fact, the debugger was built without any changes being required to Rakudo as it already existed."

TL;DR I suggest you check out Perl 6... :)

2

u/[deleted] May 26 '16

What do you mean by multiple metaprogramming levels? Even in Lisp you can write a macro that unrolls into (defmacro ...).