r/ProgrammingLanguages
What is more adaptable, more words or more symbols?
I used to like Python for its abundance of english words instead of operators which makes it more readable.
However, I have often seen the common notion where people prefer symbols over keywords. Lately, some of the newer languages have added both new keywords and new symbols.
For eg: Rust using |var| semantics for callback functions. The popular defer that has existed for very long in multiple languages. C adding [[...]] for attributes
Now even though I am saying || and [[]] are new symbols added, they aren't operators, they are just replacing some brackets essentially for a different type of task.
With this context, here is my question:
What if instead of these keywords:
await, async, defer, try, catch, weren't keywords, they were replaced by some operator?
There are two cases in my mind, either replace the keywords with a single operator (@ could replace await), annotating the data, or, use a combination of operators (-! could be used to mark a function that can produce an error).
I have the concern, that it may look too ugly because there are a bunch of operators, and in the case of combination of operators, two operators together, changing the meaning of the single operator is also weird.
But, I still wanted to ask, seeing how more experienced people view this situation.
Also, what if, both the operator and the keyword is present? Would that just be wrong because now there are two ways to do the same thing?
How do you balance a full schedule and still work on your language?
Hey everyone, I've been wondering how you all manage your time. I work from 7am to 4pm and go to university from 6pm to 10pm (UTC-3). It's been a while since I've had time to work on my language. How do you balance personal life, work, and still find time for side projects like this?
How would programming languages look if English used "," as the decimal separator?
https://www.reddit.com/r/MapPorn/comments/1tesrye/decimal_separators_used_in_europe/
Only English (including USA) uses a dot as a decimal separator. Imagine it used comma (,) instead. Pick a popular programming language and imagine how it would look, taking into account all of its historical influences.
I'd guess C would just insist on whitespace when listing stuff. That, or it would use ";" to list stuff, with I guess "." becoming a statement separator, and "\" to reach into structs, why not. 😃
List of known problems in design of existing languages?
Is there alphabetic list of desing flaws/bad ideas in various programming languages?
For exampe you might find short description of dangling-else from under d letter in list.
LjTools to generate LuaJIT bytecode for your programming language, now supports LuaJIT 2.1
github.com5 Years and $5M Later: Inventing a New Programming Language for Web Development Was a Mistake
wasp.shPhase — a statically-typed bytecode-interpreted language in C, with an essay on implementation
Phase is a statically-typed bytecode-interpreted programming language written in ~4,800 lines of C with zero external dependencies. It features a 25-opcode stack-based VM, 21 error types with source-mapped diagnostics, 5 primitive types, and a standard interpreter pipeline (lexer, parser, type checker, bytecode generator, VM).
I also wrote a technical piece on how it works by following out("Hello world!") end-to-end through every stage.
Writing: williamalexakis.com/interpreter-in-c
The current state of code generation is making me appreciate theorem provers so much more
watching the industry just blindly accept whatever an autoregressive model spits out is honestly exhausting. we are basically building software on top of glorified autocomplete that just guesses the most likely next token. it feels like mainstream programming is completely forgetting that correctness actually matters
Been messing around with Lean 4 lately just to cleanse my palate. There is something incredibly satisfying about a compiler that just flat out rejects your code if the mathematical proof doesn't close. it forces you to actually design the semantics properly instead of just brute-forcing edge cases with a dozen unit tests
tbh it feels like the only way we survive this flood of probabilistic slop is if we heavily shift our language ecosystems toward strict formal verification as a baseline. was reading earlier about how alternative architectures (like EBMs) are actually starting to max out these theorem proving benchmarks, which is kinda fascinating to see
maybe there's hope that the future of PL design won't just be about generating plausible strings of text, but actually building languages and environments where invalid state transitions are mathematically impossible to express. anyone else diving into proof assistants lately just to escape the madness?
Flower Compiler (Bootstrapped Compiler)
Hey all!
For the past few months I've been working on a language called Flower. It was originally written in C (files can be found under /vendor/) but is now fully bootstrapped (with some caveats). The goal is to eventually move toward a fully self-hosted toolchain and custom backend, but for now it transcompiles to C.
Some current language features:
- structs
- pointers (
@T) - arrays
- function definitions/calls
- manual memory management (
new/prune) - operator precedence parsing
- struct literals / array literals
- casts
- dereferencing / address-of
- control flow (
if,while,for, etc.)
Example:
struct Vec2 {
x: float,
y: float
}
float length(v: Vec2):
return v.x * v.x + v.y * v.y
end
I thought I knew a decent amount of C and programming before hand, especially considering this isn't my first time making a language in C, but I've noticed how far my skills have come especially regarding just being able to problem solve and properly organize my project structure.
Recently I added parser error recovery in v1.1.0, and after a lot of trial and error I think I've finalized my parser to a recursive-descent style approach.
Let me know any criticism, opinions, or comments you have! I'd love to get some input :)
The Borrow Checker and Rapid Prototyping
How would you feel about a language that has a borrow checker with a prototyping mode for rapid iteration? In this mode, proper annotations would still be required (failure to do so would result in compile errors) because the compiler still needs that information to reason about lifetimes, but violations of the rules themselves would result in warnings. Compiling in safe mode would be just like Rust, resulting in errors.
Do you think this would meaningfully improve iteration times for domains which require it (game dev, for example)?
Would this defeat the purpose of a borrow checker, in that most would follow the path of least resistance and not bother to clean up after themselves, resulting in an ecosystem of unsafe libraries?
Parsing Math with Pratt Parsing
I wrote a beginner-friendly blog post about Pratt parsing, hopefully it can help more people understand it. This is actually what I wanted to see when I was learning it; when I was reading Bjarne Stroustrup's book on C++ he also builds a little math parser and it is really simple to follow. The code for the full project is also available at the end of the post under the citations.
[Online BYOPL course] Build your own programming language
Hi everyone, I am new here!
Each year I teach an undergraduate-level college course on programing languages in which I start from the beginning, namely BNF grammars, and then describe parser generators, in our case Jison.
Next I introduce and cover the functional paradigm in depth. This allows us to design and implement our own functional programming language, which I call SLang, for Simple LANGuage. In this course, the implementation strategy is via interpreters. Note that I also have another course on my YT channel that explains how to build a javac compiler from scratch.
In the second half of the BYOPL course, we design and implement a non-functional version of SLang which includes non-functional features like assignment statements, sequencing, etc. We also implement recursive functions by "tying the knot".
Other topics covered in this semester-long course include the lambda calculus, eager vs lazy evaluation, six distinct parameter-passing mechanisms, infinite lists, type systems, etc.
This is a college course which I was teaching synchronously online in Spring 2021, during COVID times. I just started editing and posting those videos two days ago. I will keep posting new videos daily over the summer. You can start the course right now as it is just beginning.
If you want to check it out, here is the BYOPL course playlist:
https://www.youtube.com/playlist?list=PLIgSR01UTt8OHY8WhAqOmr8EzArJYd5Z0
On my YT channel, I also have a full discrete math course (158 videos), as well as other playlists on cybersecurity topics and a few others. Here is my channel:
https://www.youtube.com/@davidfurcy
Looking forward to your feedback!
can a language be safe and be a subset of C?
Imagine you start with the C language and then make the following changes:
- Remove pointer arithmetic. You want an array, you declare an array.
- Change the compilation of string and array literals to emit a length prefix.
- Rewrite the entire standard library so that all string and array functions enforce a length header in front of the data.
- Add RTTI to all unions and varargs so that incorrect casts fail rather than UB.
- Remove `void *`.
- Forbid malloc() without static compile-time verification that the matching free() exists (with some sort of Bounded Model Checking to sidestep a rather inconvenient Halting Problem).
Is such a language possible?
Has it ever been attempted?
IR for my compiler
Since few days, I have been working on a compiler written in python. I have successfully implemented a frontend and I want a backend to generate IR for. I have decided to make my own IR but I don't know a lot about them. Can y'all please provide me with information with types of IR, optimization tricks they utilise, and how they are implemented or work. Any type of material will be thankful.
Name for function that returns the same type of all its parameters
Hi all,
apologies for my inexperience, I'm not formally trained in CS.
I'm writing a small programming language to play around with some ideas, and I've come to the point of implementing constants folding. While doing so, I realized the AST token I use to group binary operators could probably be split in 2 different tokens instead: one for operations that return the same type of all the inputs (like addition/multiplication/etc: `add(a: T, b:T) -> T`) and one for operations that return a different type (e.g.: `greather_than(a: T, b;T) -> bool` and friends).
Out of curiosity, is there a specific name for a function whose output type is the same as the type of all its parameters ? It would help me name those 2 different categories appropriately.
Compile time evaluation
I want to include compile time evaluation in my language.
For context I have most of the language design and compiler planned out and am currently implementing it. Currently writing the parser that turns a stream of tokens into the ast. The plan is to target llvm ir for the moment.
While I have enough to do before I have to address it I want to get some information about executing code at compile time. I am explicitly not talking about macros for them I already have an idea. My questions are:
How to decide rather to execute a function or keep the call in code
Security concern about access to the system on compile time evaluation
How to execute it without writing a separate interpreter
Does llvm provide any supporting features for this
Thanks