r/ProgrammingLanguages • u/mttd • 49m ago
r/ProgrammingLanguages • u/Low_Lawyer_5684 • 6h ago
A question about handling bad typecasts in dynamically-typed language
Hello everyone,
Im developing a small hobby scripting language, for embedded applications. It was started as a PHP8 clone, but now it is not fully compatible with Zend PHP.
I would like to get a feedback on language feature Im experimenting with.
It is about type conversions (type casts)
The basic idea is to allow any conversions, but track conversions that may indicate a programming mistake (allowing a bad input to reach calculations is considered a programmer mistake).
I.e.:
Instead of immideately throwing an error or silently accepting the conversion, we can mark the resulting
value as unreliable.
This metadata (a flag) belongs to the value itself (not to the variable). Copying a value preserves the flag, and operations consuming an unreliable value propagate it to their results. 'Consuming' means using the value.
Example of the unreliable flag propagation:
Values can be tested with built-in language construct is_reliable(...);
There are pseudo-types unreliable and reliable which allow this flag manipulation:
Normally program continues executing regardless unreliability of values used.
However, you can explicitely require reliable values in a particular code section:
Reading an UNRELIABLE value inside a reliable block throws an exception.
The idea is to combine the idea of dynamic typing with the ability to enforce stricter guarantees where needed.
I'm aware that propagating unreliability through subsequent calculations is not the best way to detect a programming error at the exact point where it originally occurred :).
By the time the value is consumed, the actual source of the problem may be far away, yes.
I'm interested in whether the benefits outweight this drawback.
A fast-fail mode is also allowed: we want exception but we do not want to catch it:
Examples above are all about strings and numbers, but this mechanism is suggested for all types (hashmaps aka php arrays, float, boolean values, class instances):
What do you think about this approach?
In particular:
- Dose propagating reliability flags through values and operations makes any sense?
- Are there any problems with this model?
- Have you seen similar approaches in other languages or runtimes?
Thank you!
r/ProgrammingLanguages • u/mttd • 12h ago
Owning the Truth: Undecidability, unsound kernels, and the forging of proof
phrack.orgr/ProgrammingLanguages • u/mttd • 18h ago
What’s going on with program verification?
blog.sigplan.orgr/ProgrammingLanguages • u/naharashu • 1d ago
Help Is generating C++ instead or C or assembly bad?
.
r/ProgrammingLanguages • u/FastKnowledge_ • 2d ago
Requesting criticism I’m writing a game engine and an RPG in Duck, my own programming language
I’m building Duck, a statically typed, compiled language for game development. I’m using it to write Quaxel, my game engine, and Hellfeather, a Diablo II-inspired action RPG prototype. One of the more contentious ideas in Duck is letting the compiler infer which operations can run concurrently. I lean toward giving it that freedom, and I’d like criticism of that choice.
Here’s a small example from a Quaxel test. Each session has its own frame counter and running flag.
QuaxelSession first()
QuaxelSession second()
first.Begin()
second.Begin()
first.Advance()
first.Stop()Begin() resets a session’s frame counter and marks it as running. Advance() increments the counter if the session is running. The order of first.Advance() and first.Stop() matters. Swap them and you get a different frame count. But suppose the compiler can prove that second.Begin() touches only the second session. My instinct is that writing it on the line above first.Advance() shouldn’t, by itself, require one to finish before the other starts.
These calls are tiny. I’m using them because the dependency is easy to see. The case I care about is two expensive updates in the same frame. Even if overlapping them preserves the result, it can still change frame time and make a performance problem harder to reproduce.
If you think concurrency should require an explicit opt-in, what’s a case where you’d want that guarantee even though the compiler could prove the work independent? That’s the kind of example I’d like to test Duck’s design against.
r/ProgrammingLanguages • u/mrpro1a1 • 2d ago
Ring programming language version 1.28 is released!
ring-lang.github.ioHello
I have already released Ring 1.28
Ring is a dynamic language with lightweight implementation like Lua but with more features like Python/Ruby. I created it because I was looking for a Visual FoxPro replacement but was not satisfied with many other languages that I tried. The development started in Sept. 2013, and Ring 1.0 is released in January 2016, and I continued developing it as open-source project for over 10 years. I used to get feedback about the language through this group which contains over 3,000 topics.
So, here is what Ring is trying to do
(1) Keeping the implementation simple and small (The KISS Principle) that one programmer can study/understand in short time, but still a powerful and practical dynamic language with many useful programming paradigms.
The motivation behind this principle: Lua comes with small and fast implementation, but it misses many features provided by default in Python/Ruby. on the other hand, both of Python/Ruby requires different implementation to be used in places where Lua can be used directly, that's why there are projects like MicroPython and mRuby.
In Ring it's the same implementation everywhere. To be able to achieve this we used a custom implementation way and design decisions explained in this paper. So, In Ring, we have extreme portability, it's written in ANSI C (26 KLOC includes the Compiler, The Virtual Machine and 228 standard function), where the same implementation works on Desktop (MS-DOS, Windows, Linux, macOS), Mobile (Android, iOS) & Microcontroller (Raspberry Pi Pico).
(2) Syntax Customization: I am not a native English speaker, and I started programming at 10 years old (Three decades ago), It was a difficult journey for me at that time, I was studying English and Programming at the same time, I used to do translation from English to Arabic using a printed dictionary where I have to search for words meaning and used to spend a complete day just to read one page from my CA-Clipper programming book (for MS-DOS). Ring allows dynamic translation of language keywords/operators and supports multiple syntax styles (Similar to C, Ruby & Basic). For large/serious projects using a code formatter we force a specific style, but the point from this feature is to give each programmer the ability to write code in his native language.
(3) Declarative/Natural Language Programming (Developing Domain-Specific Languages): Ring extend OOP with new simple features that enable designing DSLs that looks like QML, SQL, COBOL, Supernova, etc. in short time. such a feature if used correctly provides advanced abstraction levels that are fun to work with.
(4) Batteries Included + Simple IDE + Form Designer: Something like VB6 era because I am coming from a Visual FoxPro background, but in Ring we can use Qt (We have packages for Qt5 and Qt6 too), and Ring supports Qt for Desktop/Android/WebAssembly, So you can open Ring IDE, design a form, run you app on Desktop, export it as Qt project for WebAssembly and run it in the browser or export it for Mobile and run it on Android. Compared to Python, Ring supports Qt for Android/WebAssembly many years before Qt company do this for Python. The reason is the principle (1), being a lightweight language with simple implementation.
(5) A love message to Visual Programming Languages: Ring Compiler/VM code is generated using my PWCT visual programming tool that I developed starting from Dec 2005. So, one of the goals was a practical project that I can develop using PWCT. After using PWCT to develop Ring, I developed PWCT2 using Ring as an example about what Ring can do. This research paper explains PWCT2 and its improvement over PWCT.
(6) Memory Management: It utilizes a deterministic, safe, and flexible scope-based memory management system that incorporates escape analysis and optional reference counting with cycle detection.
Thanks
r/ProgrammingLanguages • u/Sensitive_Mountain97 • 3d ago
Help Should I choose 1-based indexing or 0-based indexing for my programming language?
I'm creating a host-embedded, minimal, beginner-friendly programming language as a replacement for Lua. This language is really human readable, English-like and beginner friendly, with automatic memory management, automatic parallelism, a fantastic and helpful compiler inspired by Rust, and other things. The biggest question I have is whether I should choose 1-based indexing or 0-based indexing?
r/ProgrammingLanguages • u/Usual_Office_1740 • 3d ago
Serialization unit tests for a Crafting Interpreters clox bytecode vm?
reddit.comr/ProgrammingLanguages • u/Athas • 4d ago
Fixing failure handling in parallel code
futhark-lang.orgr/ProgrammingLanguages • u/thunderseethe • 5d ago
ML Modules for Mere Mortals
thunderseethe.devr/ProgrammingLanguages • u/mttd • 5d ago
Proof Assistant as Platform: Building the Next Generation of Verifiers
pirlea.netr/ProgrammingLanguages • u/yolosuperboss • 5d ago
Discussion Adding actual generics to c
I was watching tsoding's crust stream and I thought it would be so funny if I extended c to have generics.
The way I did this was by extending the syntax of c with the classic rust angle brackets to define generics and then during transpilation do some name mangling to monomorphize the generic code.
Here is the result of that abomination:
#include <stdio.h>
// you can define your own operator in fortran .op. style with a trait
trait<T> DotP {
// for parsing reasons any dot-op must have whitespaces around it in any context
T .dot. (Self self, Self other);
}
// using a very similar syntax to rust, you can add generics to structs
typedef<T> struct {
T x;
T y;
T z;
} Vector<T>;
// and by appling the trait to your struct (with generic parameters)
// you can define what your operator should do.
impl<T> DotP<T> for Vector<T> {
T .dot. (Self self, Self other){
return self.x * other.x + self.y * other.y + self.z * other.z;
}
}
int main(void) {
// by concretly defining which type you want to use as the generic
// a c struct with that/those type(s) is genenerated
Vector<float> fv = {1.0, 2.0, 3.0};
printf("Dot product of fv^2: %f\n", fv .dot. fv);
Vector<int> iv = {1, 2, 3};
printf("Dot product of iv^2: %d\n", iv .dot. iv);
}The generated c code looks something like this (I have actually implemented this transpiler, perhaps a true indicator of joblessness):
/* Generated by typedc. */
#ifndef TYPEDC_SIMPLE_GENERICS_H
#define TYPEDC_SIMPLE_GENERICS_H
#include <stdio.h>
typedef struct float_Vector float_Vector;
typedef struct int_Vector int_Vector;
struct float_Vector {
float x;
float y;
float z;
};
struct int_Vector {
int x;
int y;
int z;
};
int main(void);
static inline float float_dot(float_Vector self, float_Vector other);
static inline int int_dot(int_Vector self, int_Vector other);
int main(void) {
float_Vector fv = {1.0, 2.0, 3.0};
printf("Dot product of fv^2: %f\n", float_dot(fv, fv));
int_Vector iv = {1, 2, 3};
printf("Dot product of iv^2: %d\n", int_dot(iv, iv));
}
static inline float float_dot(float_Vector self, float_Vector other) {
return self.x * other.x + self.y * other.y + self.z * other.z;
}
static inline int int_dot(int_Vector self, int_Vector other) {
return self.x * other.x + self.y * other.y + self.z * other.z;
}
#endif /* TYPEDC_SIMPLE_GENERICS_H */r/ProgrammingLanguages • u/coolSakura • 5d ago
Discussion church pair - why do we even need to represent the first eliminator as λp. p true
This might sound like a super dumb question, but I did not want to ask Chat gpt and I wanted to ask an actual human,
but why if the first for a church pair , like has this abstraction
λp. p true and not just true.
Is it because its supposed to like take a pair as an argument and spit out the first , and thats it? cause if it were just true it would still behave the same
sry for the dumb question lol
r/ProgrammingLanguages • u/mttd • 6d ago
Fundamental limits of proofs of programs
youtube.comr/ProgrammingLanguages • u/Nuoji • 6d ago
Language announcement C3 0.8.6 - Library repositories and 30% smaller safe-mode binaries
c3-lang.orgI think I need to write a blogpost about why I deliberately nerfed dependency fetching. Why it's `c3c project fetch raylib sdl3` and not just `c3c project fetch` when the project has enough information to get them automatically.
r/ProgrammingLanguages • u/PhosXD • 6d ago
Discussion No GC, no ref-counting, no pointers, does it work?
I recently just dropped raw-pointers in my interpreted language in favor of a path-based reference type which always gives `none` if the path ever becomes invalid, unlike a pointer which would cause unexpected issues or crash the program.
Now my question is... am I missing out on anything by eventually removing the pointer type entirely? In a sand-boxed language like Ity where everything is tightly controlled & you cant really access the underlying memory of anything, does it make sense to keep pointers to values? Doesn't a path do everything you need it to? You can access storage cells just the same but it's just safer, or am I mistaken.
The idea here is to make a truly 100% memory safe design, so that you couldn't corrupt or mess with the memory even if you wanted to, but you also get to pass around references to values (which is rather required for a language that has a strict copy-everything rule).
Let me know how you would go about designing a system that can pass around references while maintaining an unbreakable wall between the program & it's memory. The way I handle it is very simple, you can only reference values that are stored as a variable somewhere or is a variable nested somewhere inside some container. This means things like temporary values cannot be referenced as they have no storage cell, which I believe is one difference between path-refs & pointers.
Another big part of my design is that everything is copied, everywhere. Passing an argument to a function copies the value, setting a variable to another one also copies the value, no matter the type. You must explicitly use a "ref" type if you want to avoid unnecessary copies. But acknowledging this, I made refs very convenient to work with. By this I mean assignment operators, arithmetic, & method calls all act on the referenced value, not the actual ref itself, making it seamless to use effectively. Of course you can still inspect properties of the ref using it's own type methods.
So yeah, that's how I went about the design of a memory safe language with simple & intuitive references. I am curious to see how your guys' *interpreted* languages went about solving references & memory safety, so do let me know of interesting alternative methods!
r/ProgrammingLanguages • u/Inconstant_Moo • 7d ago
Origins of programming languages
Pretty much all successful general-purpose programming languages were thought of by someone with a particular use-case in mind, or even just one particular use. They became successful because in trying to do whatever-it-was really well, the authors hit a larger target than they aimed for, and the more successful they became, the more this is true. Some examples, in alphabetical order:
- C was designed solely to write UNIX in. This is the poster-child for "hit a bigger target than they intended". Besides C's other merits, it came out when (a) fine control over memory and clock was important even if you weren't doing systems programming (b) the users were the sort of l33t geeks who were quite happy to stay up 'til 4 am chugging Mountain Dew and swearing at
mallocin exchange for an inner loop that goes brr. - The C++ origin story is that Bjarne Stroustrup was trying to model computers interacting in a network, and wrote a beautiful version in Simula which would take a hundred years to yield enough data; followed by an ugly version in C which was performant --- and wished, naturally, for the best of both worlds.
- Erlang (the surprise sleeper hit of languages, now the basis for Elixir and Gleam) was designed to make Ericsson's telephone exchanges more stable.
- We all know what JavaScript was designed for. It works for that, and has now been used for everything else. JavaScript is something of a special case of course, because of its association with web-browsers, but we should consider that for example Java applets failed at the same task, along with ActionScript, VBScript, JScript, Silverlight and NaCl.
- Fortran was invented to do big math and science fast. Fortran would be supplanted by later languages (C, obviously) for everything but its core competence, but before then it was used for the first adventure game, for payroll software, chess engines, CAD, mainframe utilities, and self-hosting compilers.
- Go has not unkindly been called "a DSL for writing servers".
- Haskell was invented as a platform for mathematicians to experiment with lazy functional languages, which explains pretty much everything about it.
- Lisp was invented after John McCarthy had been working for IBM on an extension of Fortran for list processing. The people at IBM were very happy with his work; he was frustrated. What he wanted, very reasonably, was to be able to automatically differentiate a function and then evaluate it, which sounds like exactly the sort of thing computers should be making easy for us. Fortran made it impossible despite its math orientation and despite the fact that McCarthy had been hired to write his own extensions to the language. The path to Lisp's homoiconicity is obvious; only slightly less obvious is why he reinvented flow-of-control as expressions. (Hint: think of differentiating a function defined by cases.)
- Julia was made for math people to do math things in.
- Lua was designed to solve the needs of scientists and engineers in Brazil's fossil fuel industry. (It became wedded to the games industry when someone at LucasFilms Games read about it in Dr Dobb's Journal and realized it was better than what they'd done in-house.)
- ML was invented as the meta-language for a theorem-prover and people who used it spontaneously demanded the language without the theorem prover.
- PHP, despite being objectively terrible, and coming from (and being aimed at) a dysfunctional "worse is better" culture, managed to spread like wildfire or a plague of poorly-designed locusts because its initials stood for Personal Home Page: it knew exactly what it was for.
- Python was created because Guido van Rossum realized that a dynamic language with powers to do OS-level things could make his life much simpler: "I thought, well, oh man, if we just could program ABC instead of C, each of those utilities would be like half a page of code and I could write the entire suite of utilities in a couple of weeks instead of the years that it looked like it was going to take us."
- Rust was famously inspired by a stuck elevator reminding Graydon Hoare of how terribly often things break, a rather more "meta" inspiration than for example C's origin story but still a moment that gave Rust a fixed purpose.
And then there's the obvious outliers:
- Java's original use-case was embedding into consumer electronics, at which it failed, so to rescue the project it was pivoted into powering "applets" (embeddable client-side applications to be embedded in HTML), at which it failed, and then it became the giant among languages that it is today because Sun Microsystems spent a billion dollars on advertising to persuade Business Idiots that this was How To Do Business Properly. There should be a law against marketing technical solutions directly to management just like there are laws against marketing cigarettes to children but what do I know?
- C# is Microsoft Java.
- Kotlin is Java redesigned by people who hated Java but didn't hate it enough.
Some things worth noting:
There are two kinds of programming languages, those written for the author, and those written for other people. And in the second case, the other people are always dumber than the author, who is talking down to them. BASIC wasn't designed because Kemeny and Kurtz needed BASIC. BASIC was designed because Kemeny and Kurtz thought that liberal arts graduates needed BASIC, because what would make things simple for their muddled little heads is a language where all values are passed by mutating global state, which is like having a bicycle for beginners where instead of having training wheels you douse it in gasoline and set it on fire.
So you will notice that none of the things on the list that are used as easy languages for n00bs were designed for that. Python was designed for Guido van Rossum to do systems programming. Lua was designed for engineers and geophysicists. JS ... * gestures broadly at the internet *. They were designed, in fact, to be ergonomic for clever people to use, and it turns out that exactly the same things make languages ergonomic for everyone to use, and that more people are clever than was previously supposed, including liberal arts graduates.
(The fact that > 50% of indie language projects are "C/C++ but better" is because the indie langdevs are all trying to scratch the same itch, they're all trying to write the systems language that they wish they could code in. These are languages written for the authors, where the authors are all very similar people who want similar things.)
The other thing that leaps out at me from my list is that the "classic" functional languages, the Lisp and ML families and Haskell, all came from math people wanting to do hard math things as their paradigmatic use-case, and anyone wondering why functional programming hasn't conquered the world yet should think about that.
(I of course have been thinking about that, and although it is premature to put Pipefish in an article about successful languages, making an FPL for writing CRUD apps has produced an language that hits different, and which can in fact be used for all sorts of cool things besides that. Watch this space for the announcement of my front-end web framework.)
r/ProgrammingLanguages • u/The2ndSlimShady • 7d ago
Cole Updates, and Version 0.1.6
reddit.comr/ProgrammingLanguages • u/dogweather • 7d ago
Is there an interactive programming language comparison/evaluation matrix?
reddit.comr/ProgrammingLanguages • u/mttd • 8d ago
Proof Repair and (Co)algebra Equivalences
arxiv.orgr/ProgrammingLanguages • u/Reasonable-Pay-8771 • 8d ago
Discussion Closures in PostScript
It appears that r/PostScript is truly dead. But I just have to talk about this PostScript stuff I've been playing with.
So, a closure is of course a function plus an environment containing the bindings of its free variables. PostScript has all that! A procedure is just an array with the executable flag set, so it can carry its own storage. It doesn't even strictly need variables because you can embed a circular reference so a procedure can access its own array as storage.
But then you can't print them out. If the procedure contains a circular reference to itself, then calling == or pstack will give you an execstackoverflow error.
So, instead we can pack the variables in a dictionary. This example generates a pseudorandom number generator using an environment dictionary.
%!
/start { 1 dict begin } def
/args { { exch def } forall } def
/clone { dup xcheck exch dup length array copy exch {cvx} if } def
/prng { {seed} start args
/env currentdict def
/func ({//env/seed get
dup -7 bitshift xor
dup 9 bitshift xor
dup -13 bitshift xor
//env/seed 2 index put}) cvx exec def
/func load end
} defPoof! a closure. seed prng generates a generator starting from that seed. You can just straight up make a copy of it at any point to have 2 synchronized generators if you wanted that. You can even see the environment and how it "captures" arguments (collect them in a dict, duh. then save the dict). It all seems so simple now. But I don't recall seeing anybody else do it.
r/ProgrammingLanguages • u/Calm-Bullfrog-6823 • 8d ago
Help How should I structure diagnostics and error reporting in a compiler written in TypeScript?
I'm making a programming language, it's based on Luau and C++ and its called L++! however im having some issues implementing diagnostics since they dont technicallly stop execution, but some of my code has typescript type errors since it relies in, stopping execution! for example normally this would work:
function foo(param: someUnion): someType {
if (someUnion.type === "coolType") {
return someTypeValue
} else {
throw new Error()
}
}
with diagnostics:
function foo(param: someUnion): someType {
if (someUnion.type === "coolType") {
return someTypeValue
} else {
//error since not all paths return someType
reporter.report(new Diagnostic())
}
}
i'd like to know how to fix this, and/or if there are any established ways to do diagnostics, thanks in advance!