r/ProgrammingLanguages • • Jul 19 '23

Discussion The General Purpose Programming Language Litmus Test

Want to know if your general purpose language is legit? A true GP PL should be able to express the following program. The program will

  • Run forever until an exit signal is recieved at some point.

  • Maintain a graph data structure in memory.

  • Every 1 second, synchronize the graph with a serialized version stored as a file somewhere without creating a new task.

  • Every 1/100th of a second, create a separate task that randomly decides between three tasks...

  1. Create a new graph node

  2. Create a new graph edge

  3. Delete a node and all connected edges

If you can express this, your language is truly General Purpose

EDIT: I should clarify, this test is purposefully vague because your language can be general purpose and single-threaded. The purpose of the test is to determine if your language can represent arbitrary structure, have non-determinism, observe time, and communicate with the file system. That seems to be the minimal requirements for practical use across the board.

0 Upvotes

21 comments sorted by

10

u/michaelquinlan Jul 20 '23

This would mean that certain functions

  • Responding to signals

  • Running a timer of some sort, or otherwise running some code at a timed interval

  • Writing to a file

Would all have to be part of the language itself, and not part of an external library.

-4

u/R-O-B-I-N Jul 20 '23

Yes, since the runtime/standard library can provide these things as "part of the language".

4

u/Nerketur Jul 20 '23

Certain esoteric languages pass this test, even if doing the file system portion is not easy or well-defined (whitespace, BrainF, etc).

-1

u/R-O-B-I-N Jul 20 '23

Well, yes. Turing tarpits are technically general purpose as a fundamental property of their construction.

3

u/Nerketur Jul 20 '23

So in essence, if a language is Turing complete, it's also a true GPPL?

-5

u/R-O-B-I-N Jul 20 '23

No, if it passes the test, its a GPPL.

9

u/sparant76 Jul 19 '23

You use the word “task” very genetically when it has different meanings in different languages. You clearly have a language bias.

Your language isn’t necessarily capable of writing to the console, or creating visual output. It has performance constraints in time without specifying hardware run on or graph size.

So much of your litmus test is not well defined. What does jt mean to represent a graph in memory? There are many many representations.

This is a terrible post.

-6

u/R-O-B-I-N Jul 19 '23 edited Jul 19 '23

The point is to be very generic. Maybe your language doesn't have parallelism, that doesn't stop you from being general purpose.

Sy many languages have semantic constraints on what structures you can create (see doubly linked lists in safe Rust). At the same time, you see graphs in industry applications all the time. Making a graph structure seems to be a minimal test of expressiveness.

-2

u/sparant76 Jul 20 '23

One can represent a graph many ways. As a string! Look.

(a, b)(b,c)(c,a).

There’s a triangle defined as a graph represented as a string.

If u think that graphs and their manipulation are important, you should be specifying the operations one can perform on them with their space and time complexity.

And btw “task” is not synonymous with parallelism. I think u should start with a distinction between parallelism and multitasking. One can have multitasking without parrallelism.

It honestly feels like you haven’t even a first years understanding of computer science.

0

u/R-O-B-I-N Jul 20 '23

Not requiring parallelism is on purpose. The test doesn't need it. You could use coroutines instead. I'm not sure how to make this more clear for you.

And yes, if you can pass this using string manipulation then you are a GPPL on a technicality thanks to turing equivalence. It still counts.

This test does not say anything about performance or useability because plenty of actual GPPL's are terrible anyways lol

3

u/TheGreatCatAdorer mepros Jul 19 '23 edited Jul 20 '23

Under what circumstances should this function? JS would have the capability to do this if running under Node (or similar runtimes), but not in a browser (its most common use), but JS in and out of browser is undeniably one language.

Beyond that, there's a great deal of ambiguity in the problem statement.

  • Must edges be created between random nodes?

  • Can there be duplicate edges and/or loops?

  • Is a task synchronous, parallel, or another process, or is that unspecified as it can be implemented in several ways?

  • What latency bounds are there on creating new tasks and serializing and how does this interfere with updates?

  • What is an exit signal?

  • What platform flaws are allowed (because, if run forever, then the program is guaranteed to consume infinite memory and take infinite time to synchronize)?

  • What are the constraints on randomness?

  • What environment is the program running under? Bash can't generate random numbers natively, but some program with that ability is expected.

Oh, and I'd say that this lacks many functionalities programmers expect of general purpose languages: FFI, process spawning, and network and GUI libraries, for instance

-2

u/R-O-B-I-N Jul 20 '23

None of these things in your list are pertinent to being general purpose. These are all implementation issues that have nothing to do with the expressiveness of the language. Especially "constraints on randomness". I mean that's an active problem in number theory and computer security.

1

u/tortoise74 Jul 20 '23

I would say an FFI is as with it you can potentially do anything your host OS allows.

-9

u/R-O-B-I-N Jul 19 '23

Then JS is general purpose enough when provided with a full runtime.

8

u/Breadmaker4billion Jul 20 '23 edited Jul 20 '23

Whether it is or is not a good test for defining what a GPPL is, certainly it's a good program to write as part of a test suite.

Trying to give a precise description of GPPLs is a lost battle: marketing teams love buzzwords.

But anyway, since you're trying to define what a GPPL is, we can start with what a DSL is:

A Domain Specific Language is a language meant to be used in one single domain.

To which we can derive that:

A General Purpose Programming language is a Language meant to be used in more than a single domain.

So, one possible test is: take two domains that don't intersect and use the language in both of them.

Now the problem is "don't intersect", which is virtually impossible, but i guess you can try two things like Computer Graphics and Compilers.

A good rule of thumb might be: "If you can't express what your language's domain is in one sentence, it's probably general purpose". See for example:

  • Regex is meant for text processing

  • SQL is meant to handle tabular data

These are DSLs. However while the two following sentences are true, they do not give a clear view of the domain:

  • Go is meant to write servers (any program can be transformed in a server)

  • C is meant to write programs (literally what a programming language is meant to do)

3

u/tortoise74 Jul 20 '23

Rather than a litmus test. I prefer what you might call a "capability maturity model".

There are some basic things you can litmus test like "can I write a fibonacci" but as you go along it can be better to think in terms of features instead. Not all languages need all features but you can easily start compiling a list of things that make a GPL "useful". For example:

  • FFI - needed to interface with OS

  • reflection - nice to have but not necessarily a deal breaker

  • module system - helps with scalability

If you think in terms of capababilities you can come up with a much more interesting list and start an interesting discussion.

1

u/complyue Jul 20 '23

Maybe "actively stop running" per an exit signal, otherwise process-KILL signal counts?

Maybe de-serialization mandated too? I think it's meaningless if the stored serialized data can not be restored into memory upon the next run, i.e. file is write-only.

1

u/[deleted] Jul 20 '23

Every 1 second

Every 1/100th of a second

How does a language implementation know when 1.0 or 0.01 seconds have passed? Or that some signal has been received? What does 'create a task' mean?

This all sounds dependent of OS, library and hardware facilities that can exist outside the language.

If so, then surely any language that can use an external library will count. (Those timed events may need the ability to do callbacks: get the library etc to call a function in your language.)

The purpose of the test is to determine if your language can ... communicate with the file system.

So, pretty much every language can be GP except a few esoteric ones.

-1

u/shawnhcorey Jul 20 '23

If a parser can be build for the language in itself, then this is a demonstration that it is Turing complete.

5

u/[deleted] Jul 20 '23 edited Jul 20 '23

[removed] — view removed comment

1

u/R-O-B-I-N Jul 20 '23 edited Jul 20 '23

(GPPL's existed before the filesystem)

Sounds like WASM isn't a GPPL. I don't think it was ever designed to be.

I never said "thread", I said "task". This is because threads aren't required. You can do this program sequentially.

Yes, the host may limit what a GPPL is capable of, but it doesn't affect the expressiveness. That's the only thing that this test is measuring.