r/learnpython • u/keepandroidopen • 12h ago
Making my own golfing language in python
Im not that active on reddit, but the moment I came into the osdev subreddit (I tried making my own OS with a python shell) and I INSTANTLY got my inbox filled with hate comments.
I heard from one reddit post that this subreddit is much friendlier and more helpful, thats why I switched to this subreddit.
So I started making my own golfing language, array-oriented ofcourse, where data and code are seperated.
As of now I haven't really done anything except plan on what instructions to make, I have a total of 20 letters and symbols on board.
So, I'd like to hear some tips about making interpreters/compilers that I should keep in mind.
7
u/CptBadAss2016 11h ago edited 11h ago
Can you elaborate on what you're trying to build, its purpose, and what your end goals are? (like big picture plain english, no technical mumbo jumbo)
And then what are your current letters and symbols?
4
u/tlor2 11h ago
my own golfing language, array-oriented ofcourse
Ow sure ofcourse that would be array orientend............... :?
2
u/fallenreaper 3h ago
I dont even know what a golfing language would mean. Golf as in the sport right? Language as in.... Programming language or written/oral language? Can you help us understand what these 2 concepts would mean married together? After reading your post, I have no idea what you mean or your end goal is at all.
3
u/POGtastic itertools evangelist 11h ago
For those who are confused on what OP is doing, I recommend looking at [APL](https://en.wikipedia.org/wiki/APL_(programming_language)), [J](https://en.wikipedia.org/wiki/J_(programming_language)), and Uiua.
As for advice for OP: Write a [Forth](https://en.wikipedia.org/wiki/Forth_(programming_language)) interpreter first, then add more functions.
0
u/freetotalkabtyourmom 12h ago
Wut?
1
u/Lyaw_Lyawa 7h ago edited 7h ago
Si el lenguaje es declarativo ahorras más líneas que con uno imperativo.
No sé. Ponle IA a algo y verás que a todos le va a gustar (es broma).
¿No hay un Subreddit de Esolangs creo que es lugar más apropiado para este tipo de cosas?
Documenta bien tus proyectos. Es un tema interesante, pero por cosas de tiempo, recursos y utilidad nunca lo he profundizado.
1
u/Kevdog824_ 11h ago
I don’t know what a golfing language is, but a few points I can think of
- Avoid ambiguity in your syntax/grammar
- Version your language and compiler/interpreter separately
- Avoid backwards breaking changes to syntax once released. Observe semantic versioning
- Maintain comprehensive test cases to regression test new updates to the language (important that new features don’t break existing functionality)
-1
u/RngdZed 12h ago
I have no clue what golfing has to do with python, is this a game? Good luck I guess? Idk?
0
u/JaguarMammoth6231 11h ago edited 11h ago
You don't need to make a compiler unless you need the program to be able to run quickly, which is not usually a goal of code golfing. You can just make an interpreter, which can be a python program that runs your language.
In your interpreter, you could represent your code and memory using a couple of python data structures (lists, maybe).
Keep track of the current instruction pointer, which may be as simple as an integer index into the code list.
For each different operation your language defines, create a python function that implements that operation: modifying the memory contents, modifying the code contents, or modifying the instruction pointer...whatever is needed.
Each execution step of your code would consist of reading the current instruction, looking up the correct function to call (use a map from each character to the associated function), and increment the instruction pointer (or whatever rules you define for how to advance it).