Author Topic: My language  (Read 639 times)

Krice

  • Protector of the @
  • *****
  • Posts: 2094
    • View Profile
    • Email
My language
« 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.
« Last Edit: February 15, 2018, 03:50:21 PM by Krice »

Krice

  • Protector of the @
  • *****
  • Posts: 2094
    • View Profile
    • Email
Re: My language
« Reply #1 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.

TheCreator

  • High Priest
  • ****
  • Posts: 365
    • View Profile
    • Fame
    • Email
Re: My language
« Reply #2 on: February 22, 2018, 03:16:09 PM »
What's the advantage over existing languages?
Fame (Untitled) - my game. Everything is a roguelike.

Krice

  • Protector of the @
  • *****
  • Posts: 2094
    • View Profile
    • Email
Re: My language
« Reply #3 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.

Avagart

  • 7DRL Reviewer
  • Protector of the @
  • *
  • Posts: 549
    • View Profile
Re: My language
« Reply #4 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.
« Last Edit: March 20, 2018, 03:11:27 PM by Avagart »

mushroom patch

  • Protector of the @
  • *****
  • Posts: 554
    • View Profile
Re: My language
« Reply #5 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.
« Last Edit: March 20, 2018, 10:22:47 PM by mushroom patch »

Krice

  • Protector of the @
  • *****
  • Posts: 2094
    • View Profile
    • Email
Re: My language
« Reply #6 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.

Krice

  • Protector of the @
  • *****
  • Posts: 2094
    • View Profile
    • Email
Re: My language
« Reply #7 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.