Discuss Scratch

__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

(a, b){a + b}(10, 10)
NFlex23
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

(a, b){a + b}(10, 10)
That's going to be pretty hard to parse without lookahead.

Assuming that you use parenthesis for grouping expressions, that is.

Last edited by NFlex23 (Oct. 12, 2023 14:31:09)

__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

NFlex23 wrote:

__Falcon-Games__ wrote:

(a, b){a + b}(10, 10)
That's going to be pretty hard to parse without lookahead.

Assuming that you use parenthesis for grouping expressions, that is.
You can also do this but idk why you would want to.

Standard.Function({ a+b }, args=["a", "b"])(10, 10)

Last edited by __Falcon-Games__ (Oct. 12, 2023 14:33:38)

ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

You can also do this but idk why you would want to.

Standard.Function({ a+b }, args=["a", "b"])(10, 10)
Wouldn't this raise an error in your lang since the variable doesn't exist in scope?
__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

ajskateboarder wrote:

__Falcon-Games__ wrote:

You can also do this but idk why you would want to.

Standard.Function({ a+b }, args=["a", "b"])(10, 10)
Wouldn't this raise an error in your lang since the variable doesn't exist in scope?
Could you explain what you mean?
ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

ajskateboarder wrote:

__Falcon-Games__ wrote:

You can also do this but idk why you would want to.

Standard.Function({ a+b }, args=["a", "b"])(10, 10)
Wouldn't this raise an error in your lang since the variable doesn't exist in scope?
Could you explain what you mean?
Standard.Function({ a+b }, args=[“a”, “b”])(10, 10)
The part in red contains the variables for the block, but they are referenced as strings. The part in blue is a literal code block, so the code would probably be evaluated at actual runtime, not at function runtime. Since the variables haven't been declared in the code block, it would raise a variable lookup error, unless you make it so the variables exist in the block scope

Last edited by ajskateboarder (Oct. 12, 2023 14:56:31)

__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

ajskateboarder wrote:

__Falcon-Games__ wrote:

ajskateboarder wrote:

__Falcon-Games__ wrote:

You can also do this but idk why you would want to.

Standard.Function({ a+b }, args=["a", "b"])(10, 10)
Wouldn't this raise an error in your lang since the variable doesn't exist in scope?
Could you explain what you mean?
Standard.Function({ a+b }, args=[“a”, “b”])(10, 10)
The part in red contains the variables for the block, but they are referenced as strings. The part in blue is a literal code block, so the code would probably be evaluated at actual runtime, not at function runtime. Since the variables haven't been declared in the code block, it would raise a variable lookup error, unless you make it so the variables exist in the block scope
When the function is defined it adds them to the scope of the callback so when it's called it doesn't cause an error.
rdococ
Scratcher
1000+ posts

Custom Programming Languages

Here is a dynamic, purely object-oriented scripting language I've been working on in the past few days.

The main concept behind it is that objects are scopes. You can wrap any code in `(| object scope |)` and any variables and functions defined within become properties and methods of the resulting object.

You can construct standalone objects:
bob := (|
name := "bob";
talk -> print("Hello there!");
|);

print(bob name);
bob talk;

Define classes, which are now just functions using object scope:
Person(name, age) -> (|
name := name;
age := age;

greet(stranger) -> (
print("Hello there, " ++ stranger name ++ ", I'm " ++ name ++ "!");
);
birthday -> (
age <- age + 1;
print("It's my birthday today!");
);
|);

alice := Person("Alice", 23);
bob := Person("Bob", 21);

bob greet(alice);

And even perform pattern matching for functional programming styles:
map(list, func) -> list match (|
empty -> list;
cons(head, tail) -> Cons(func call(head), map(tail, func));
|);

map(List(1, 2, 3), (x) -> x * 2);

Now I just need to finish it and decide on a name

Last edited by rdococ (Oct. 12, 2023 22:37:58)

ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

rdococ wrote:

Here is a dynamic, purely object-oriented scripting language I've been working on in the past few days.

The main concept behind it is that objects are scopes. You can wrap any code in `(| object scope |)` and any variables and functions defined within become properties and methods of the resulting object.

snip
Looks very satisfying, but would this language let you run any code at class instance creation time? Otherwise, this is just like any other OOP language, in my opinion

Last edited by ajskateboarder (Oct. 12, 2023 23:51:41)

PlNG_
Scratcher
500+ posts

Custom Programming Languages

rdococ wrote:

Here is a dynamic, purely object-oriented scripting language I've been working on in the past few days.
snip
1. Is it treewalked, bytecode-compiled or native-compiled?
2. Will it have foreign function interface?
rdococ
Scratcher
1000+ posts

Custom Programming Languages

PlNG_ wrote:

rdococ wrote:

Here is a dynamic, purely object-oriented scripting language I've been working on in the past few days.
snip
1. Is it treewalked, bytecode-compiled or native-compiled?
2. Will it have foreign function interface?
1. Interpreted to start with, but I'll see if I can transpile it to JS. The trickiest part is handling non-local returns.
2. Not for now, though that would be a fun idea for the future.
NFlex23
Scratcher
1000+ posts

Custom Programming Languages

ajskateboarder wrote:

rdococ wrote:

Here is a dynamic, purely object-oriented scripting language I've been working on in the past few days.

The main concept behind it is that objects are scopes. You can wrap any code in `(| object scope |)` and any variables and functions defined within become properties and methods of the resulting object.

snip
Looks very satisfying, but would this language let you run any code at class instance creation time? Otherwise, this is just like any other OOP language, in my opinion
It looks like you can customize the “class function” (the constructor) with the code you need at creation time. In fact, if you look at this example, that is what is already happening (specifically the parameters in the Person function):
Person(name, age) -> (|
name := name;
age := age;

greet(stranger) -> (
print("Hello there, " ++ stranger name ++ ", I'm " ++ name ++ "!");
);
birthday -> (
age <- age + 1;
print("It's my birthday today!");
);
|);

alice := Person("Alice", 23);
bob := Person("Bob", 21);

bob greet(alice);

Last edited by NFlex23 (Oct. 13, 2023 12:15:48)

ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

NFlex23 wrote:

It looks like you can customize the “class function” (the constructor) with the code you need at creation time. In fact, if you look at this example, that is what is already happening (specifically the parameters in the Person function):
Person(name, age) -> (|
name := name;
age := age;

greet(stranger) -> (
print("Hello there, " ++ stranger name ++ ", I'm " ++ name ++ "!");
);
birthday -> (
age <- age + 1;
print("It's my birthday today!");
);
|);

alice := Person("Alice", 23);
bob := Person("Bob", 21);

bob greet(alice);
This means it has to create all of these functions at class instantiation, right? That wouldn't be particularly efficient

Maybe it can cache function code so it doesn't have to be interpreted every time class instances are made, but not cache top level code like property assignments or any other code? Probably not wording this correctly

Last edited by ajskateboarder (Oct. 13, 2023 12:35:23)

NFlex23
Scratcher
1000+ posts

Custom Programming Languages

ajskateboarder wrote:

This means it has to create all of these functions at class instantiation, right? That wouldn't be particularly efficient

Isn't that how instance methods always work? Or am I missing something?
ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

NFlex23 wrote:

ajskateboarder wrote:

This means it has to create all of these functions at class instantiation, right? That wouldn't be particularly efficient

Isn't that how instance methods always work? Or am I missing something?
I mean, if it doesn't usually work like that, I guess this would be a cool innovation. Whatever language the interpreter is written in could look at class functions, transpile (?) it into the native interpreter language, store it in a dict/table/etc. and run that code when class instances are made and instance functions are initialized

Last edited by ajskateboarder (Oct. 13, 2023 12:59:16)

rdococ
Scratcher
1000+ posts

Custom Programming Languages

NFlex23 wrote:

ajskateboarder wrote:

Looks very satisfying, but would this language let you run any code at class instance creation time? Otherwise, this is just like any other OOP language, in my opinion
It looks like you can customize the “class function” (the constructor) with the code you need at creation time. In fact, if you look at this example, that is what is already happening (specifically the parameters in the Person function)
Any code can go inside the object brackets. They're essentially parentheses with special semantics; instead of returning what the code inside returns, they return the resulting scope as an object.

ajskateboarder wrote:

I mean, if it doesn't usually work like that, I guess this would be a cool innovation. Whatever language the interpreter is written in could look at class functions, transpile (?) it into the native interpreter language, store it in a dict/table/etc. and run that code when class instances are made and instance functions are initialized
Yeah, I think I can do something like that.
__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

One of my scrapped programming language ideas was Stem. Take a look yourself.
(_importer_ => {
(importer => {
(catch => {
(try => {
(f _init_ => {
(doc "This is a module for managing counters")
<= (counter 0)
})
}),
(except err => {
(if err then (error "Could not import"))
})
})
})
}) <= {
_state_ => {
(f counter value => {
(f _init_ => {
(doc "This will return the value of the counter")
<= counter
}),
(f increment => {
(doc "This will increment the counter")
counter => { counter + 1 }
}),
(f decrement => {
(doc "This will decrement the counter")
counter => { counter - 1 }
}),
(f set value => {
(doc "This will set the counter to the provided value")
counter => value
})
}) <= {
_state_ => {
counter => 0
}
}
}
}
ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

One of my scrapped programming language ideas was Stem. Take a look yourself.
snip
Looks obviously confusing – callback hell as a language

I once thought of an English-based language which is kind of similar to Gherkin
# printing
say "Hello world"
say 42

# def variable
make a variable named "best string number" with value of: "12"

# get variable
say (get value of "best string number")

# set variable
set variable "best string number" to: "12"

# def function
make a function named "my function" that does:
say "42 auuugh"
give "done"

# call function
call "my function"

say (call "my function") # done

# debugging
debug
breakpoint

# assertions
make sure ((call "my function") is "done")
make sure (1 is 1)
make sure (1 > 12)

# numbers (includes 32-bit, 64-bit, floating point numbers, and complex numbers)
make a variable named "best real number" with value of: 12
make a variable named "also real number" with [number] value of: 1+2i
make a variable named "best real float" with [number] value of: 0.1

# math operations (must be in parenthesis)
make a variable named "some number" with value of: (2(1*12+1))

# boolean evaluations (must also be in parenthesis)
make a variable named "some bool" with value of: (2 > 1)

# square roots just use sqrt(). It's treated as an expression rather than a function

# multi-line string variable
make a variable named "best string" with value of: "Hello
world"
That was the basic stuff. Here's the stuff for lists:
# def list
make a list named "my list" with values:
- "12"
- 123
- 12+8i
- (2(12+1))

# reassign list
set list "my list" with values:
- "12"
- (2(12+1))

# add and remove list items
add to list "my list" the values:
- "asdfghjkl"
- "zxcvbnm"
- "qwertyuiop"

# access list stuffs
say (get "1st" value of "my list")
say (get value of "my list") # prints string representation of list
IDK, I'm not working on this and I just came up with a partial spec

Last edited by ajskateboarder (Oct. 13, 2023 15:40:47)

__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

ajskateboarder wrote:

__Falcon-Games__ wrote:

One of my scrapped programming language ideas was Stem. Take a look yourself.
snip
Looks obviously confusing – callback hell as a language
It's not that confusing if you look at it for a moment, it's a beautiful callback helly functional paradigm. I name it prod-functional.
I scrapped it because of it being too verbose but I do wonder what are your main concerns with it?
gilbert_given_189
Scratcher
1000+ posts

Custom Programming Languages

(after looking at some other languages people have made, I've realized that this kinda resembles another language here…)

I had an unfinished proglang that only has the (abstract) interpreter and parser done called Gravy. Its name is a corruption from “curry”, as in currying, which this language uses a lot. That might make it a highly functional language (which, depending on your defintion of “highly functional”, it might be), but it defines some object-oriented paradigm like the object-like “scopes”. (thus, the corruption on the name)

Things to note on this language:
  • Keywords (so this, `hello world`, and ~!@#$%^&*) are atoms (primitive types like numbers and strings). You can store it on fields or pass it as a value on a function. In fact, this is essentially how you do operations to other atoms, since:
  • Every atom act as functions. Though it's mostly for selecting which operation to perform, it nevertheless accepts some input.
    For example:
    1 + 1
    is interpreted as:
    1(+)(1)
    which returns 2 as another number.
  • Fields (which is created by a scope) is also an atom. You can even assign a field into a field if you really want to:
    print {
    a := 1;
    print (a !); # This prints 1 `(without the ! it will print "(a := 1)")`
    inner_scope := {
    b := 2
    };
    c := (inner_scope b);
    c ! := 3;
    }; # This prints "{a := 1; inner_scope := {b := 3;}; c := (b := 3);}"
    Note the # function, which is a special function that given any input, returns # itself. This is useful for commenting code, although it's kinda useless since it defeats the norm that “the interpreter can't read comments”.
  • Each line is executed as currentScope(atom1)(atom2)(atom3)…(atomN).
    For example:
    1 + 1;
    is interpreted as:
    currentScope(1)(+)(1)
    As a scope (which, by the way, is also an atom, even though it could be subdivided unlike an atom), it returns back anything that is not a keyword. So, this code just returns the number 2.
    Parenthesis are used to access the current scope in the middle of an argument. For example:
    print (a + 1);
    is interpreted as:
    currentScope(print)(currentScope(a)(+)(1))
    When a scope got a keyword as an input, it returns a field of that name, creating one if it doesn't exist. In this case, the keyword print is a built-in function, while a is the current scope's own field.
    Except special keywords like := for assignment, ! for fetching, and ? for identification, fields will return the value stored on itself, called by the given input.
Currently these mechanics are not being implemented:
  • A way to make inner scopes be able to access fields of parent scopes
  • More builtin functions
  • Custom functions (need to implement the interpreter first)
  • Control structures (the interpreter needs to be done first)
  • Lazy evaluation? (this may require the interpreter to be revamped)
  • Bits
  • Iterators?
  • Import system (though this may not be implemented)
  • many more…

Last edited by gilbert_given_189 (Aug. 7, 2024 10:04:30)

Powered by DjangoBB