17 ms·
Show HN: I created a language called AntiLang – breaking all the conventions
AntiLang is an interpreted programming language written in Go.
The basic idea of this is to keep all the logical parts of a language same, but reverse the structure of it.
The idea for this project came when I was having a long midnight conversation with my friend and thought of writing such a weird language. The initial draft was far worse than the current implementation; we thought of reversing the brackets and the language would be read from bottom to top. I'm happy that I dropped that idea
Technical details:
As the interpreter is written in Golang, I compiled it to WASM, and the whole interpreter is running in the browser.
For the editor, I'm using Monaco, the same library that powers the text editor in VSCode.
I learnt how to build it while reading "Write an Interpreter in Go" by Thorsten Ball.
The project is opensourced - https://github.com/SirusCodes/AntiLang https://github.com/SirusCodes/AntiLang - do give it a star if you like the project.
- gaff33 2y agoEveryone knows 'goto' is bad, so a language like this needs 'comefrom'
- SirusCodes 2y agoInteresting thought... But how will that work? The statement would be executed only it comes from that line?
- immibis 2y agoIt is reverse GOTO. After (or before - your choice) that line is executed, execution jumps to the comefrom.
- SirusCodes 2y agoI don't know how I'm going to implement it but seems pretty interesting flow. Raised issue - https://github.com/SirusCodes/AntiLang/issues/7 https://github.com/SirusCodes/AntiLang/issues/7
- lloeki 2y agoI see no mention of INTERCAL in this thread, which implements COME FROM If you don't know about it, you're in for a treat. https://en.wikipedia.org/wiki/INTERCAL https://en.wikipedia.org/wiki/INTERCAL The joke runs longer: https://en.wikipedia.org/wiki/COMEFROM https://en.wikipedia.org/wiki/COMEFROM
- ambigious7777 2y agothat's absolutely evil
- movpasd 2y agoThe compiler inserts a goto to the statement following the comefrom statement into the line specified. :^) If multiple comefroms to the same line are specified, the comefrom to jump to is selected randomly.
- GuB-42 2y agoIt is like a regular goto, but with the label and statement reversed. So instead of label: do_something goto label You have comefrom label do_something label: Really, that's just syntax. Declare your labels with "comefrom", and ":" means "jump". But it looks a lot more confusing this way.
- jezzamon 2y agoINTERCAL already has this in its language
- jwpapi 2y agough I like it but I had to close the tab right away
- changexd 2y agoa very good language this seems to me like
- dev-jayson 2y agoThanks for reminding me how reading code feels when I just got started.
- SirusCodes 2y agoWe all have been there
- acosmism 2y agoI had fun, lost my mind, and a few friends.. probably. thanks!
- x3n0ph3n3 2y agoI wonder if this can be considered an info hazard. Nice job, but don't do it again.
- SirusCodes 2y agoI will try my best to resist the temptation ;)
- gunian 2y ago[flagged]
- rf15 2y agoA good effort and took me a minute to adjust to not knowing what's going on. Title made me hope for something more esotheric than just backwards code, though.
- SirusCodes 2y agoI'm sorry to disappoint you, maybe next time I will have something more esoteric
- Bolwin 2y agoThe control flow is basically smalltalk funnily enough, since it has effectively no language level control flow, if/while etc are all just messages in the form of ``` [condition] whileTrue: [code] (condition) ifTrue: [code] ifFalse: [code] ```
- SirusCodes 2y agoA lot of people at Reddit told me that it resembles SmallTalk, Factor, and Forth. Being someone who started coding in last decade I have only heard the names but never saw the syntax, but true it looks surprisingly similar. I can't really fathom that people actually built stuff in those language (probably better things that we build today)
- nagaiaida 2y agoapl-family languages also often read easier right to left
- dlcarrier 2y agoPostfixes are easier to use, if you know how to use them. They're not only used in programming but also in spoken language: It is how, in this sentence, the verb works. It isn't how the verb works, in this sentence. Sentences that simple are equally understandable using the verb as a postfix or infix. When sentences get longer that changes, though: It is how, in this sentence, which now has an extra clause, the verb works. It isn't how the verb works, in this sentence, which now has an extra clause. In the first sentence, it's clear that the extra clause is something the sentence has, not the verb. The second example has what is called a dangling modifier, which is a clause at the end of the sentence that ambiguously could be describing more than one thing, in this case it could mean that either the sentence has an extra clause or the verb has an extra clause. The lack of ambiguity also means it takes fewer commands to describe a single operation. For example, in an calculator with infix notation, which is what most people learn, calculating the multiple of four pairs of sums would require the following keypresses: ( 5 + 6 ) x ( 2 + 7 ) x ( 3 + 8 ) x ( 7 + 9 ) = With an RPN calculator, which has a postfix notation, it would only require these keypresses: 5 Enter 6 + 2 Enter 7 + 3 Enter 8 + 7 Enter 9 + x x x That's 24 in the first example and 19 in the latter, a reduction of over 20%. My grandma never really learned how to use a computer and was generally not very good at complex instructions. When she learned to use a calculator, RPN was just as common as postfix notation, and she was able to figure out how to use RPN, but had trouble figuring out postfix notation. Nowadays, schools usually only teach postfix notation, so most students aren't exposed to the easier method, and will have to do extra work, in the short term, to lean it, but it means calculations will require less work, once learned. tl;dr: Postfix notation is the Dvorak keyboard to infix notation's Qwerty keyboard. The former is easier and faster, but everyone learns the latter. Putting in the extra work to learn the former will save you more time in the long run.
- protocolture 2y agoReminds me of RPL https://en.wikipedia.org/wiki/RPL_(programming_language) https://en.wikipedia.org/wiki/RPL_(programming_language) I wouldnt discount your work. Someone who thinks a bit different might find it a workable onramp into coding where others have failed.
- deleted 2y ago[deleted]
- snovymgodym 2y agoThis is what perl looks like to people who don't know it.
- chuckadams 2y agoShouldn’t the interactive mode be called `antilang lper`?
- SirusCodes 2y agoGood point, but repl is just fine in my opinion
- knome 2y agoyou may want to take a peek at INTERCAL. you think GOTO is bad? wait until you have to deal with COME FROM, especially in "Threaded INTERCAL" where arriving at the location that multiple active COME FROM statements are pointing to simply jumps to all of them simultaneously.
- drdec 2y agoIs COME FROM significantly different from an event-driven architecture?
- fc417fc802 2y agoNot in the sense of flow of execution. But you'd explicitly fire off an event, no? COME FROM is registering invisible triggers at arbitrary locations.
- kryptiskt 2y agoC# has a new feature, interceptors, that is very COME FROM like. https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12#interceptors https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/cs...
- SirusCodes 2y agoMight implement this feature. Raised an issue on GitHub - https://github.com/SirusCodes/AntiLang/issues/7 https://github.com/SirusCodes/AntiLang/issues/7
- fc417fc802 2y agoDoes the language have continuations? If you're going for fun control flow features those are both much more useful and mind bending. They also fit the theme you have going since most languages don't have them and they're effectively the reverse of a function call.
- SirusCodes 2y ago
- thezipcreator 2y agoHonestly, it doesn't look that bad, I could get used to that syntax. It's not really objectively worse nor better than the normal syntax we have in programming languages now. I think a true AntiLang would also break conventions of how programming itself works too. This just seems like a normal language with weird syntax.
- semolinapudding 2y agoThis makes me wonder whether the usual order for function application is an artifact of the S-V-O sentence structure in western European languages. Maybe if Euler had been raised in a language with a S-O-V sentence structure, we would write (x)f instead. Plus, reverse function application/composition works better with our tendency to write the domain of the function before its range. Given f : A -> B and g : B -> C, the composite function is written as g o f which is mildly annoying.
- susam 2y agoEven in modern mathematics, the postfix notation is used in some places. One example I can recall is permutations. Consider the following permutation: f = (1 2 3 4) (1 4 2 3) This is typically written in cycle-notation like this: f = (1)(243) If we look at the cycle notation, f maps each symbol to the one on the right. For example, it maps 1 to 1, 2 to 4, 4 to 3, and 3 to 2. Now if we want to find out what happens to the sequence (4 3 2 1) when we apply f to it, we normally write it as (3 4 2 1)f The argument comes first. The function name comes next. It makes it quite convenient to work with permutations, composition of permutations, etc. For example, the result for the above application is: (3 4 2 1)f = (3 4 2 1)(1)(243) = (2 3 4 1)
- wging 2y agoYou see it in some treatments of abstract algebra too. (Which are not unrelated to permutations in any case.) I think at least one book used in my undergrad used postfixes for function application, but I can't remember which.
- twnettytwo 2y agoWas it perhaps 'A course on Group Theory' by John S. Rose?
- wging 2y agoDefinitely not. (He may do that, I just hadn't ever heard of that book before today.) I think it was one of Isaacs, Herstein, or Artin, but I'm a bit too lazy to dig through my old books at the moment.
- susam 2y agoMaybe I've spent too much time with Forth, but the given example didn't look bad at all to me. Quite the contrary. The moment I reached line 2 (i.e., ",20 = count let"), I knew exactly what was happening. My mind immediately switched to postfix-mode. From there, everything made sense: logical, intuitive, even aesthetically pleasing!
- SirusCodes 2y agoA lot of people said this, why building this I had no idea of how these languages looked. Now that I know about them my project looks like a cheap imitation of them :(
- mkingston 2y agoDon't be disappointed. That's cool! You've independently discovered something.
- susam 2y ago>>> Maybe I've spent too much time with Forth, but the given example didn't look bad at all to me. Quite the contrary. [...] >> A lot of people said this, why building this I had no idea of how these languages looked. Now that I know about them my project looks like a cheap imitation of them :( > Don't be disappointed. That's cool! You've independently discovered something. I completely agree with mkingston's comment. Whether or not this project resembles other programming languages is beside the point. What truly matters is the joy you had building it. As Alan Perlis wisely said, "I think that it's extraordinarily important that we in computer science keep fun in computing." This is a fascinating project, and in that same spirit of playful exploration, I'd like to share a minimalist, esoteric postfix language for drawing on a canvas that I built some time back: <https://susam.net/fxyt.html https://susam.net/fxyt.html>.
- baq 2y agoBreaking conventions has been a thing for about as long as conventions themselves. No need to be hard on yourself. Next thing you should look at is Malbolge, very convention-breaking ;)
- someothherguyy 2y agojumbled seems like a better name
- SirusCodes 2y agoSomeone suggested MirrorLang, that's fitting as well.
- another-dave 2y agoThink you should rename some of the keywords to more naturally suit their positioning. Like, rather than [condition] if <code> [condition] else if <code> else <code> if you have [condition] then <code> otherwise [condition] then <code> otherwise (Though 'otherwise [condition] then' breaks your pure postfix style). Similarly "while" could be "yields". And "let" could be "over" (CB radio-style): 10 = age over;
- SirusCodes 2y agoSomeone on X suggested to make it logically reverse, so true would be false and visa versa. We can go ahead and make + behave as - and similarly for other operators.
- wging 2y agoDo you want to lie to your users, or do you just want to use unconventional operators? If the latter, you could consider using something like ruby's `unless`. (the number of times I've noticed code that does `unless !some_condition`... which is of course just the same thing as `if some_condition`)
- SirusCodes 2y agoMakes sense; I need to think about which would be better.
- rjmill 2y agoI love it. I want a python-esque version that's whitespace sensitive. But only for trailing whitespace.
- jedberg 2y agoYou're a demon living in hell, aren't you? No one on Earth could be this evil.
- SirusCodes 2y agoThat is something I might do... Seems pretty horrible
- LoganDark 2y agoWhy need it be trailing at all? Just use Whitespace (esolang)
- cluckindan 2y agoPolyglottism
- donatj 2y agoThe idea of a trailing whitespace sensitive language is... amazing. Get real torturous with it and make the amount of whitespace the line number, ala BASIC. 3 trailing spaces is line 3 for instance. Tab character counts as powers of ten separator? Space space space tab space space is line 32?
- daotoad 2y agoIf you used leading whitespace you could wind up with something like old basics where you had to number your lines. It was great, you'd always skip 10 between lines so if you had a bug you could stuff a patch in between existing lines at *5. For the whitespace, you'd have to know how deeply to indent the outermost part of your code. So if you add an if block to a for loop, every line of the code has to be indented and only the contents of the new if would be at indent of 0. I am not going to write this pseudocode in AntiLang because I am not that much of a masochist. for ( foo in somearray ) doStuff(foo) end becomes for ( foo in somearray ) if ( condition ) doStuff(foo) end end If you antilanged this the rest of the way, you could have a common `start` to indicate the start of a block and then replace the `end with the actual conditional. start doStuff(foo) for( foo in somearray ) This gets horrible pretty quick. So as terrible as trailing line space is, leading line space is quite possibly worse. Which leads me to the ultimate conlusion - White space should be balanced. If you need 4 spaces indent, you also need 4 spaces on the end of the string.
- quuxplusone 2y agoMore or less just writing each line backward (token by token). Q1: How close could one get to a grammar that would basically recognize C with each line reversed character-by-character? Q2: What would a language look like where instead of being oriented into right- or leftward-marching lines, it was oriented into downward-marching columns?
- sulam 2y agoHonestly, you have done the most superficial thing here. It’s fine, but K is much more interesting in terms of encoding ideas differently than ALGOL style languages, just as one easy example.
- SirusCodes 2y agoDidn't knew that it existed, I will take a look at it!
- 29athrowaway 2y agoThis looks very readable compared to APL
- croo 2y agoNice! Feature request : conditional expressions should start with the "else" branch.
- SirusCodes 2y agoThat's a good idea but the current flow is from top to bottom but this would change that, someone would be reading it from top to bottom then at the end read if case then go back to top to read else case. I don't want to do that.
- drpixie 2y ago> Initially I thought to use , for float but ended use using . for floats. Better - check the computer's region setting and use the local language convention, so decimal point is "." is English speaking regions, and "," is Euro regions, and who knows what else in other regions. That way code might work in one location but fail in another ;)
- seafoamteal 2y agoGood idea, but I suggest swapping . and , regions keeping with the spirit of the language.
- SirusCodes 2y agoIs that true? I thought for all languages only "." is defacto decimal point in all languages. Never knew it changes with locale.
- plopilop 2y agoThe hegemony of software only accepting . has de facto pushed the standard everywhere for computers, but here in France I still write with a comma, but type with a dot. A few years ago Excel and some other softwares started to be locale dependent and I never wanted to burn my computer this much
- johncoltrane 2y agoFrench dev currently working for a French but global client, here. The UI of the timesheet app is in English but the fields only accept `,` as decimal point. It's so needlessly confusing.
- bayindirh 2y agoThat's one of the great boons of localization. The webapp knows you're in France, so it tries to do the right thing, while giving you a US English UI. I experience the same thing, but got used to it somehow. Another good example is how "İ" is popping up everywhere, even in English, because of misconfigured locale settings and how changing case is affected by it. We (Turks) are responsible for that, sorry (We have ı,i,I,İ =D ).
- Uptrenda 2y ago[flagged]
- SirusCodes 2y agoWhy so much hate for rust?
- zombot 2y agoIt doesn't break conventions, it just uses them backwards. Is it even a true postfix language?
- thih9 2y agoOff topic, tongue in cheek - I thought we agreed that it's just PHP? There was an old meme about it: - "PHP: a fractal of bad design": https://news.ycombinator.com/item?id=3820431 https://news.ycombinator.com/item?id=3820431 - An image of a double clawed hammer that someone actually made: https://c2.staticflickr.com/8/7226/7095238893_5000f6e57d.jpg https://c2.staticflickr.com/8/7226/7095238893_5000f6e57d.jpg - And of course there were follow up images: https://imgur.com/CO1tv https://imgur.com/CO1tv
- ale42 2y agoFunny, some of the "reverseness" looks a bit like PostScript, which is a stack-based language, where you write code like: /Times-Roman findfont 12 scalefont setfont 42 84 moveto (Hello world) show showpage
- card_zero 2y agoGood old Reverse Polish notation, reminds me of Robowar. https://robowar.fandom.com/wiki/Introduction_to_RoboWar https://robowar.fandom.com/wiki/Introduction_to_RoboWar
- SirusCodes 2y agoPretty interesting game, never heard about it. Thanks for sharing.
- keyle 2y ago,fantastic pretty that's ,this about joke we but 10-15% of the world reads rtl...
- SirusCodes 2y agoI knew this, before posting here I thought all programming languages are ltr. But now I know a lot of programming languages did rtl like forth, factor, postlang, etc
- magnat 2y agoC-like equality (==), inequality (!=) and assignment (=) is such a missed opportunity here. One could go with "=", "=/=" and "<-" here while both preserving some sanity and shock factor.
- SirusCodes 2y agoThat's a pretty good idea, I can do this. Raised an issue for this - https://github.com/SirusCodes/AntiLang/issues/5 https://github.com/SirusCodes/AntiLang/issues/5
- Joker_vD 2y agoThat's Algol/Pascal's equality operator, Erlang's inequality operator (Pascal used "<>") and Haskell's binding operator (or whatever it's actually named inside the do-notation). In fact, Algol designer's considered using "<-" for assignment.
- G_o_D 2y agoMake it like urdu language which is written in reverse
- ludamn 2y agoLol this entire thing is just funny, thanks for the laughs!
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- _gmkt 2y ago)) 1 x (define ( )) "مرحبا، هذا ليسب!" (print ( )) x 2 + (print (
- cluckindan 2y agoYou need to right-align this.
- ivan_gammel 2y agoSome more suggestions: 1. replace "while" with "go on" (yes, with space, because why not) { i < 10 } go on [ ... ] 2. add break statement in the form of "oh, come on!" { i < 10 } go on [ ,1 += i { i > 5 } considered [ oh, come on! ] ] 3. replace "if" with "considered" and "if else" chain with "on <number> thought". Final "else" must be "eigentlich", because who said all keywords should be in English? {a < b } considered [ ... ], {a > b} on 2nd thought [ ... ], eigentlich [ ...] 4. add reverse array function with special syntax, because it is special: reverse{array} 5. add constants: ,$SCREAM!$ = SCREAM let it be 6. Add System.exit(<number>): ,{1}oh, no! 7. Add exceptions: {$Invalid user$}oh, my god! 8. Do not support catching exceptions in try blocks. They are exceptions. Every function must implicitly return an union type <ReturnValue|Exception>. If exception value is not handled, it pops up. ,{1; 0}divide = value let {exception is value} considered [ ,value print ] on 2nd thought [ ,1+= value ]
- SirusCodes 2y agoThanks, those are some pretty nice suggestions!
- earth2mars 2y agoYou should have called it "Tenet"
- behringer 2y agoMissed gold. You should have had a new assignment operator and you could have used single equals sign for checking equality.
- SirusCodes 2y agoWe can introduce a breaking change... I have raised an issue for this - https://github.com/SirusCodes/AntiLang/issues/5 https://github.com/SirusCodes/AntiLang/issues/5
- betimsl 2y agoReads nicely from right to left.
- saghm 2y agoThe best terrible (or worst, I guess!) idea I've ever had for a language is using fuzzy matching for variable names. No need to worry about typos, since something close enough will work, and as long as you've defined at least one variable, you'll never have an undefined error!
- Simon-curtis 2y agoYou should start an If/else from the else case and use unless keyword. { return 1; } unless 8 == 3 { return 2 }
- lambdaone 2y agoWhy limit your changes to syntax? Intercal's COME FROM would be a good addition, but you definitely also need SOLVE and PROVE statements to increase the power of the language. Having IF TERMINATES and IF NOT TERMINATES predicates would be useful, too. Why limit yourself to everyday computable functions? And if you really wanted to, you could implement both SOLVE and PROVE in terms of them...
- SirusCodes 2y agoYep, someone suggested it; I might add it. ref: https://news.ycombinator.com/item?id=43192484 https://news.ycombinator.com/item?id=43192484