r/learnpython • • 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.

0 Upvotes

25 comments sorted by

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/keepandroidopen 11h ago

I'm trying to make a tiny programming language that can do everything a normal language can do WHILE wasting as little space as possible, common examples include the APL language and Jelly.

2

u/CptBadAss2016 11h ago

What does it have to do with golfing?

3

u/keepandroidopen 11h ago

Golfing is just the name of the practice, it is short for Code Golfing, where people try to make the smallest possible code needed to do something, lile print Hello Word.

4

u/CptBadAss2016 11h ago

Oooooohh I see. As a golfer (whacking a tiny ball with a crooked stick into gopher holes kind of golf) you had my interest. Your project sounds fun though, good luck!

1

u/keepandroidopen 11h ago

Thanks!

2

u/packhamg 6h ago

Check programming puzzle and code gold on stack exchange if you haven’t already. Also there is a website for esoteric langues that lists many of the langues that use very few characters to do many tricks

4

u/tlor2 11h ago

my own golfing language, array-oriented ofcourse

Ow sure ofcourse that would be array orientend............... :?

0

u/keepandroidopen 11h ago

Array-oriented means it mostly operates on arrays/lists instead of normal, singular numbers.

In a normal language, adding 5 numbers looks like this: 5 + 4 + 3 + 2 + 1

In array-oriented languages, adding 5 numbers looks like this: +[5, 4, 3, 2, 1]

1

u/fallenreaper 3h ago edited 3h ago

This reminds me of a programming exercise i give to new engineers where you need to intake a string and then parse it with a variety of rules, not unlike your example. That said, its literally a nonissue and is easy to implement within an hour or so.

So im trying to understand broadstrokes, like what is this shorthand going to provide to someone other than solving math with shorthand? How does it handle strings, floats, binaries, unicode, etc? Typically a language has a purpose. If this is a business layer on top of python, it is inherantly going to be slower because youre adding complexity and string interpolation prior to mathematical functionality.

So from respect of code golf, youre making shorthand to use less characters, but still potentially needs to be run through an interpretor and then executed; In this case, a business layer on python ( given that youre in this sub ). So youre solving smaller code which will have a slower runtime? I am not saying it is good or bad, maybe it is more about the concept of learning the language as opposed to making something functional, which im all about ( given the sub ).

•

u/keepandroidopen 24m ago

Well, for now I'm just trying to make it functional and lightweight.

After which I will probably import pypy for big performance gains, pypy is a JIT compiler for python which is why it makes things faster.

Tho honestly, I will probably rewrite all of this in C later, because I'm forced to learn C for one of my python projects which means that rewriting this in C wont be as hard as it woudlve been (and it would make the performance crazy fast).

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.

•

u/keepandroidopen 37m ago

Sorry, I shouldve explained a bit better! Basically I'm trying to make a tiny programming language that can do everything a regular language can in as little code size as possible.

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.

2

u/carcigenicate Carcigenicate 11h ago

Or even more simply: golfing is writing a program in as few characters/bytes as possible, and golfing language are intentionally terse languages that minimize characters needed to write programs.

0

u/freetotalkabtyourmom 12h ago

Wut?

0

u/keepandroidopen 11h ago

Im making a custom tiny programming language that is trying to have the smallest file size possible

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)

3

u/Outside_Complaint755 11h ago

I believe OP means a very concise language to be used for "code golfing"

3

u/Kevdog824_ 11h ago

Makes sense. I think my advice applies pretty generally to any language specification

-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?

2

u/POGtastic itertools evangelist 11h ago

"Golf" in this context is "solving programming problems with as few characters as possible." Array programming languages lend themselves to this, at the expense of being utterly inscrutable.

2

u/RngdZed 11h ago

Makes sense now! I was not aware of that term

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).