Temple of The Roguelike Forums

Development => Programming => Topic started by: Krice on February 15, 2018, 03:48:18 PM

Title: My language
Post by: Krice on February 15, 2018, 03:48:18 PM
I've thought some ideas, like loops that have a "inside" value that could be accessed.

Code: [Select]
repeat 10
     print "the value is " repeat.value

In case of multiple loops you could use a "reference" by writing repeat 10 as x. ('as' could be generic reference keyword.) Also, the value would go from 1 to 10, not from 0 to 9.

Until would work like 'while' in C++, but same as repeat:

Code: [Select]
until 0=5
    print "the value is " until.value
    until++

In that example 0 is the initial value and when 5 it breaks out.
Title: Re: My language
Post by: Krice on February 17, 2018, 04:01:43 PM
Function syntax looks like this:

Code: [Select]
function myfunc
integer a:0 //: is a parameter with default value 0

if a=0 return true

return 10 //gives error, first return determines the type


myfunc(1)
myfunc(a:1) //target variable, not everything has to used

The class looks pretty much same. But while I have been thinking about class I wouldn't want to do it in the way C++ does it. I think private part of the class is mostly useless, because in real life you anyway get into situation where you want to access data with get/setters, and so being private doesn't really protect the class. Also, protected keyword in C++ is just adding to confusion.
Title: Re: My language
Post by: TheCreator on February 22, 2018, 03:16:09 PM
What's the advantage over existing languages?
Title: Re: My language
Post by: Krice on February 22, 2018, 05:22:01 PM
What's the advantage over existing languages?

I don't know yet. I got stuck when thinking about functions and classes. This is a kind of thing where you would need to actually try things, although it's possible to try them in theory, only harder. Implementing a language (compiler) is probably quite difficult.

One of the problems with classes and modular programming is that do we need more protection (of data) or less? For example if classes always had private data, it could make programmers write better modular code. At least in theory.
Title: Re: My language
Post by: Avagart on March 20, 2018, 03:04:47 PM
Quote
Just an update, I've gone so far as started to write imaginary code with my own language! No but it's kind of fun. This far I've managed to write code that doesn't have () or {} characters, I noticed you don't really need them and without them the source code is actually more readable.

You inspired me to play with that idea. I kinda like it, but I encountered some issues already. Intendation-based scope is not my favorite idea, and writing that kind of parser is more difficult. So, I'd need some scope indicators... and begin [...] end approach is not better than brackets. Also manual end-of-line symbol will help. And here, our syntax is inconsistent already.

Quote
Implementing a language (compiler) is probably quite difficult.
But creating transpiler that would generate, for example, C code is not overly complicated - at least for simple language.

Quote
Code: [Select]
function myfunc
integer a:0 //: is a parameter with default value 0

And how would you implement local variables to distinguish them from function arguments?

Btw, probably syntax is not the most important part of designing programming language.
Title: Re: My language
Post by: mushroom patch on March 20, 2018, 10:18:56 PM
Code: [Select]
repeat 10
   repeat 10
     print "I've called Krice an imbecile" repeat.value "time(s)"

Fun language, Krice. The best thing is that I don't know what the output of my program is even though it is based on one of the simplest and best known programming constructs there is.
Title: Re: My language
Post by: Krice on March 21, 2018, 10:57:05 AM
Fun language, Krice. The best thing is that I don't know what the output of my program is even though it is based on one of the simplest and best known programming constructs there is.

If repeat is 'nameless' then it's the one you last used. In this case it's repeating 1-10 ten times.
Title: Re: My language
Post by: Krice on March 21, 2018, 10:58:49 AM
And how would you implement local variables to distinguish them from function arguments?

integer a=0

= for local variables and : for parameters.
Title: Re: My language
Post by: Krice on May 16, 2018, 07:20:33 AM
I think checking some value could be written as

Code: [Select]
if a is 5
if a is not 8

At least in cases of = to keep it for assignment only.
Title: Re: My language
Post by: Krice on May 17, 2018, 09:14:47 AM
Type design is I guess "kind of" interesting problem when you try to decide what built-in types to have. For example types in C are closely related to hardware (how many bits the type has) and bit-based architecture has of course problems with precision numbers which in part go over my head because math. But in concept level, what built-in types to have? Also, it could be interesting to have a "type class" to define low level types. How it would work I have no idea. When you think about it the type systems of most languages are quite primitive, probably because they have been kept that way since bit-based computers were invented.
Title: Re: My language
Post by: Krice on May 18, 2018, 09:15:40 AM
Lists could be an important part of the language and they could be mixed type with type information and also a name for the item, something like this:

Code: [Select]
a = 1:n, "red":str, 3.4:real, true:b

a.n++
a.str += " apple"
a.real -= 1.2
a.b = false

You could also access a[index] with list index. I'm not sure how list of lists would work in syntax level.
Title: Re: My language
Post by: Vosvek on May 20, 2018, 02:22:44 AM
Out of curiosity, why not just use Python, Ruby, F#, or COBOL, as your syntax/goals are similar to those languages?

On assignment versus equation, is there really an issue with using "=" and "==", respectively? When I first started programming it was a little confusing, sure. However, using only "=", which changes based on context, would only have confused things more, and the semicolon versus equal sign just makes the language look inconsistent. Alternatively, why not differentiate "assign" from "equals" like so:
Code: [Select]
function myfunc
integer a = 0

if a equals 0 // Use equals, rather than = or ==
return true
else
return 10 // Error, first return determines the type


myfunc(1)
myfunc(a = 1)

Also, why not just decide whether you want static or dynamic?
Code: [Select]
bool fooBar(int lhs = 0, int rhs = 0)
return lhs equals rhs

print "Is LHS equal to RHS? "
print fooBar(rhs = 2, lhs = 1) // I think this is what you intended when you wrote myFunc(a:1) (that is, any-order parameter assignment)
print newline

Your last code example also doesn't really make much sense. Why not just assign things with a name properly, as it'd be annoying to refactor the "a" tuple, forgetting that it can only ever hold one value of a single type:
Code: [Select]
data aData
int n = 1
string str = "Apple"
real r = 3.4
bool b = true

void fooBar(aData a)
a.n++
a.str += ", Apple"
a.real -= 1.2
a.b = false

void reflectionFunc(data d)
if d has int n
n++
if d has string str
str += ", Apple"
if d has real r
r -= 1.2
if d has bool b
b = false

aData a
// fooBar(a)
reflectionFunc(a)

* * *

lastly, have you looked into Jonathan Blow's 'JAI' programming language (link (https://www.youtube.com/watch?v=gWv_vUgbmug))? He's not focused on syntax as of yet, but you might still find it interesting (actually, perhaps more so as he doesn't focus on syntax). :D
Title: Re: My language
Post by: Krice on May 21, 2018, 09:33:49 AM
I think this topic is too advanced for your chip/ai type.
Title: Re: My language
Post by: Vosvek on May 21, 2018, 09:59:01 AM
I think this topic is too advanced for your chip/ai type.

Perhaps. But when an individual transcends sarcasm, it's hard to know when to take their ideas even remotely seriously. Regardless, I find syntax interesting. :D
Title: Re: My language
Post by: Krice on May 30, 2018, 07:46:54 AM
Why would you even need =, why not something like this:

Code: [Select]
declare a "this is a string"
declare b 1.0
var c 5

Or maybe uppercase style:

Code: [Select]
DECLARE a 5.4, c 5, s "str"

ENUMERATION e
one
two
three

VARIABLE v 5

DECLARE struct
a 0
b 0.0
c ""

VARIABLE struct
a 0
b 5
Title: Re: My language
Post by: Vosvek on May 30, 2018, 09:43:27 AM
So sort of like a combination of Javascript and Assembly?

How would you reassign a variable within a struct? Also, how would you than +=, -=, <=, or >=? Should they really all be words? I mean, I want the ugliest language possibly, but it ought to be consistent. ;)

Code: [Select]
let WeekdayEnum
    Monday
    Tuesday
    Wednesday
    Thursday
    Friday
    Saturday
    Sunday

let FooBarStruct
n       1
str     "Apple"
real    3.4r
b       true

let structFunc(FooBarStruct a)
increment   a.n
add         a.str   ", Apple"
subtract    a.real  1.2
let         a.b     false

let reflectionFunc(var o)
if o has int n
increment n
if o has string str
add str ", Apple"
if o has real r
subtract r 1.2
if o has bool b
let b false

let a FooBarStruct
structFunc(a)
reflectionFunc(a)
Title: Re: My language
Post by: Krice on June 17, 2019, 10:07:46 AM
I've been reading some pages from 'Language Implementation Patterns' by Terence Parr. This is supposed to be a light weight book, but it's still pretty hard core I would say. I don't really understand a lot, but the book is I guess about parsing languages and it's talking about stuff like complexity of C++. If you think about it C++ (also the C part of it) is quite complex and sometimes ambiguous. You have stuff like pointer arithmetics and const keyword which can be placed almost anywhere. Thinking about that it would be interesting to create a simple language with restricted ways to do things, even if it means you have to write more code.
Title: Re: My language
Post by: TheCreator on June 18, 2019, 06:26:30 AM
Guess what. Such a language has already been created. It's called Java. But I don't see anything interesting in it :P. If you like being restricted, write in Java. If language's complexity motivates you rather than intimidating you, write in C++. If you want to waste your lifetime creating yet another useless language that will save the world...
Title: Re: My language
Post by: Krice on June 18, 2019, 06:53:01 AM
Such a language has already been created. It's called Java. But I don't see anything interesting in it :P.

I don't think Java is a simple language. I think it removed pointers? I'm actually not that familiar with Java. But I know some languages began from a "need" to fix C++ problems (like pointers) which I think is a silly way to think about it. Even C++ wants to fix itself by new versions.

Quote
If you want to waste your lifetime creating yet another useless language that will save the world...

I've already wasted my life so it doesn't matter that much. Besides nothing we do is that important if we get philosophical. Creating a language is something I see an interesting idea, because working with C++ and knowing a bunch of other languages I have a strange feeling that things could be done in some other way.
Title: Re: My language
Post by: TheCreator on June 19, 2019, 06:46:19 AM
I don't think Java is a simple language. I think it removed pointers?

It's not simple, it's simpler than C++ (in terms of syntax). They haven't removed pointers, only wrapped them in "references", which makes them harder to control. But let's look at C++. In addition to "normal" pointers it also has function pointers, class method pointers and object data member pointers (but it does not have object method pointers, which adds to the confusion). Additionally, since C++11 we have 3 new types of so called smart pointers and now-deprecated auto_ptr. That's already 8 different types of pointers. There's also something called reference, which is nothing more than a different syntax for a pointer. And, since C++, r-value references. This way we end up with 10 pointer types, more or less incompatible with each other. C++ allows to create levels of indirection with pointers (but luckily not with references!), so that we can also have pointers to pointers or even pointers to pointers to pointers to pointers to pointers. And I'm not going to talk about all possible combinations of "const", "volatile" or "const volatile", placed before or after the '*' (although this is pure fun). Did I mention iterators? Of course, iterator is yet another concept of pointers, with totally different syntax and usage... Enough?

I think Java now seems pretty straightforward and friendly, but I sometimes wonder how novices must feel when they encounter a "null pointer exception" time after time, with all those people telling them that Java has no pointers :).
Title: Re: My language
Post by: Krice on June 19, 2019, 12:18:02 PM
I think we can agree that C++ is a complex language. That was kind of the point, maybe languages could be simpler and force the programmer to follow more strict rules, in a good way. In fact I don't quite understand why C++ is so complex, what was the reason for that? Maybe backwards compatibility with C, but then why C was/is that complex? Was it because that's how they were thinking about languages back in 1960's and 70's when most of them were invented, who knows.
Title: Re: My language
Post by: Krice on June 27, 2019, 12:52:03 PM
Another way to make languages easier to use would be a higher level thingy created on top of an existing language. Some languages compile to C (or whatever), but I was thinking more like a "construction kit" for some language. For example it would be really nice to have a graphical design tool for planning class hierarchy in C++. It would make the first phase of modular (as in what file contains certain classes) design and also class hierarchy design much easier. I guess those kind of tools exist, but not in freeware/open source.
Title: Re: My language
Post by: Vosvek on June 28, 2019, 03:36:53 AM
I think we can agree that C++ is a complex language. That was kind of the point, maybe languages could be simpler and force the programmer to follow more strict rules, in a good way. In fact I don't quite understand why C++ is so complex, what was the reason for that? Maybe backwards compatibility with C, but then why C was/is that complex? Was it because that's how they were thinking about languages back in 1960's and 70's when most of them were invented, who knows.
C really isn't as complicated as people say, you just need to be a little patient with it and think through what you're actually trying to achieve. Yes, you don't have namespaces or structs with associated functions and private variables (object classes), there is no built-in boolean type (and stdbool sometimes conflicts with old libraries), and strings/char */char[] are awkward, but it's not that difficult to work around these limitations, or understand why the languages works the way it does. Not to mention, these very limitations can give you a different perspective on how you design your code, and push you towards alternative approaches like object pools and relational databases, both of which come with the benefit of knowing exactly where your memory lives, where leaks could occur, and how everything can be coupled, decoupled, or associated. It's especially simple by comparison to C++, for better and worse. :)

C backwards compatibility for C++ definitely adds to C++'s complexity. But it doesn't help that the C++ community is divided between OO patterns + 'RAII, not raw', and 'Stop abusing OO'. On one hand, there's a crowd that effectively wants Java/C# but with RAII pointers and manual/no garbage collection (C++ has been on this path for a while, D was almost there, but backed out, and Rust seems to be heading this direction), and on the other hand, there's a crowd that wants C, but cleaner and with some of the tools from C++ (which is the current mob voicing their concerns over C++'s future, and resulting in languages like Jai, and Unity's Burst Compiler). As a result, C++ is stuck in the middle, trying to cater to both, satisfying neither, and has become a kitchen sink full of dirty dishes. You'll find whatever you need in there, but you'll have to sift through the slime and clean it first.

Another way to make languages easier to use would be a higher level thingy created on top of an existing language. Some languages compile to C (or whatever), but I was thinking more like a "construction kit" for some language. For example it would be really nice to have a graphical design tool for planning class hierarchy in C++. It would make the first phase of modular (as in what file contains certain classes) design and also class hierarchy design much easier. I guess those kind of tools exist, but not in freeware/open source.

Isn't that what parser generators (i.e. YACC, ANTLR, Yeti, etc.) and compiler toolchains (i.e. LLVM, GCC, etc.) are for? Or are you talking about visual programming languages, or visual programming languages specifically designed for building scripting languages?

As far as I'm aware, Visual Studio does have a graphical C++ class designer. I know they definitely exist for C# and Java (and in all honesty, they're quite finnicky and not as useful as just hammering in code yourself, which is a shame).

As an added, you've probably already seen it, but Bob Nystrom is currently working on a book about creating scripting languages. It might be worth checking out if you haven't already: https://craftinginterpreters.com/ (http://"https://craftinginterpreters.com/")
Title: Re: My language
Post by: Krice on June 28, 2019, 07:42:10 AM
I'm clearly not thinking about C++ the same way. OOP is mostly a structural thing that helps in organizing the code. It's not a complex thing at all compared to everything else in C/C++.

The "class construction kit" would create the files and empty classes (or with some variables if defined) for the whole project. Then you would have the class hierarchy ready, which I think is sometimes difficult to understand and create when you just start to write the source code without plans.
Title: Re: My language
Post by: Vosvek on June 29, 2019, 07:28:05 AM
I'm clearly not thinking about C++ the same way. OOP is mostly a structural thing that helps in organizing the code. It's not a complex thing at all compared to everything else in C/C++.

The "class construction kit" would create the files and empty classes (or with some variables if defined) for the whole project. Then you would have the class hierarchy ready, which I think is sometimes difficult to understand and create when you just start to write the source code without plans.

OO is not complex, but the strive for "greater" OO support directly contributes to the messier, complex parts of C++.

That still sounds like a class diagram/designer, which Visual Studio has had since 2005.
Title: Re: My language
Post by: Krice on June 29, 2019, 07:51:52 AM
That still sounds like a class diagram/designer, which Visual Studio has had since 2005.

Well, at least you have to install it in VS2019 which I did, after all these years not knowing about it.
Title: Re: My language
Post by: Krice on July 13, 2019, 04:30:44 PM
"Language Implementation Patterns" by Terence Parr was difficult to understand and for the most part I didn't, but it has started me thinking about simpler version of languages. For example when you think about class, struct and namespace in C++ they are more or less the same thing and there should be only 'class' keyword for all purposes. Enums are bad in C++, because they are basically ints and add lots of confusion, so they should also be removed. It's interesting to think about a version of C++ with actual OOP paradigm and simpler structure.
Title: Re: My language
Post by: TheCreator on July 15, 2019, 05:55:38 AM
For example when you think about class, struct and namespace in C++ they are more or less the same thing and there should be only 'class' keyword for all purposes.

Once again, that's Java. And Java is a great example of how simplifying a language in one place leads directly to making it much harder in another. What we have now in C++ just reflects the complex nature of programming. Java tries to hide the complexity by using sophisticated abstractions, but this of course does not remove the complexity. But as long as you are not a startup owner thinking about conquering the world with 10000 high school interns, the existence of 'class' an 'struct' in C++ should not be a big obstacle for you.
Title: Re: My language
Post by: Krice on July 15, 2019, 10:51:41 AM
Once again, that's Java. And Java is a great example of how simplifying a language in one place leads directly to making it much harder in another.

I always thought Java more or less as complex as C++. Maybe it has removed some things that C++ has, but there seems to be plenty of keywords in java. I think most modern languages are way too complex and large. Like python, swift, C# etc. Not only the language, but libraries on top of that.
Title: Re: My language
Post by: Krice on May 11, 2020, 08:28:30 AM
This is the way switch-case would work.

Code: [Select]
switch i
case 0
print "case 0"
case 1
if x is 5
break
print "case 1"
cases 2 ... 8
//range version
default
//default case

Each case would have automatic break (even empty ones, or possible empty cases would be illegal), but you could group them with a range.
Title: Re: My language
Post by: Vosvek on May 23, 2020, 05:04:57 AM
Nice work, Krice. Hopefully we'll see your thoughts on includes/imports/packages just in time for Easter next year. At this rate, your language will be compiling in no time.
Title: Re: My language
Post by: Krice on June 08, 2020, 05:39:59 AM
I've been reading "Beginning COBOL for Programmers" by Michael Coughlan. It's not a language I would use, but it's an interesting look at programming before the invention of function (which COBOL doesn't have (well, user defined functions, it does have some wacky internal ones)). Also, I've began to code with python and I think it's a nice language, although probably slow when it's not a compiled language. I'm leaning more to the idea that creating a better (whatever it is) language would not be a solution to some basic problems in game development at least, because it's much more design than programming. It's just something that you think about when working with crude languages of today.