Author Topic: My language  (Read 43249 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • 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

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • 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

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • 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

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • 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
  • Rogueliker
  • *
  • Posts: 567
  • Karma: +0/-0
    • 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

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • 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

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • 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

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • 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.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #8 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.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #9 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.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #10 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.

Vosvek

  • Guest
Re: My language
« Reply #11 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)? 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

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #12 on: May 21, 2018, 09:33:49 AM »
I think this topic is too advanced for your chip/ai type.

Vosvek

  • Guest
Re: My language
« Reply #13 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

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #14 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
« Last Edit: May 30, 2018, 08:58:50 AM by Krice »