Discuss Scratch

__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

rdococ wrote:

__Falcon-Games__ wrote:

-snip-
Interesting… what does the ‘summary = expand(summary)’ line do?
It will pass the variables on the current scope as arguments to the function which has been expanded.

ajskateboarder wrote:

__Falcon-Games__ wrote:

So to create an object in Sandwich you don't need to create classes first, here's how you do it.
import Console

fun main() {
obj = Standard.Object(a=1, b=2, c=3)
Console.out(obj.a, obj.b, obj.c)
}
1
2
3
Reminds me a lot of JavaScript objects - very powerful feature - but not a very huge fan of the Standard.Object declaration. Seems a bit too verbose compared to using braces, yes?
It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?

TheSecondGilbert wrote:

__Falcon-Games__ wrote:

So to create an object in Sandwich you don't need to create classes first, here's how you do it.
import Console

fun main() {
obj = Standard.Object(a=1, b=2, c=3)
Console.out(obj.a, obj.b, obj.c)
}
1
2
3

And for classes.
import Console

class Fruit(type) {
fun summary(type) {
Console.out("I am a fruit of type " ++ type)
}

type = type
summary = expand(summary)
}

apple = Fruit("apple")
Console.out(apple.type)
Console.out(apple.summary())
apple
I am a fruit of type apple
Could this be a bit easier? (for example, calling `object` instead of `Standard.Object`)
That would imply it's in the current scope and not part of the standard scope, something like Standard.Obj might work better. object could also be a link to Standard.Object to say.
rdococ
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

It will pass the variables on the current scope as arguments to the function which has been expanded.
Huh… I take it your functions don't capture variables from their scope automatically?

__Falcon-Games wrote:

It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?
How about `Std.Object`, based on the C++ syntax for namespaces, `std::`?
ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

ajskateboarder wrote:

__Falcon-Games__ wrote:

So to create an object in Sandwich you don't need to create classes first, here's how you do it.
snip
Reminds me a lot of JavaScript objects - very powerful feature - but not a very huge fan of the Standard.Object declaration. Seems a bit too verbose compared to using braces, yes?
It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?
Maybe move “Object” and other datatypes into a seperate library that you specifically import? Like “import Object from Datatypes”
__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

rdococ wrote:

__Falcon-Games__ wrote:

It will pass the variables on the current scope as arguments to the function which has been expanded.
Huh… I take it your functions don't capture variables from their scope automatically?
Not their parent scope, the object. If you mean the object's scope then yes.

__Falcon-Games wrote:

It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?
How about `Std.Object`, based on the C++ syntax for namespaces, `std::`?

That could work but still kinda lengthy.

ajskateboarder wrote:

__Falcon-Games__ wrote:

ajskateboarder wrote:

__Falcon-Games__ wrote:

So to create an object in Sandwich you don't need to create classes first, here's how you do it.
snip
Reminds me a lot of JavaScript objects - very powerful feature - but not a very huge fan of the Standard.Object declaration. Seems a bit too verbose compared to using braces, yes?
It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?
Maybe move “Object” and other datatypes into a seperate library that you specifically import? Like “import Object from Datatypes”
Making everything an import is not what I want. I think I am going to make an operator be the constructor for object automatically like $ or % maybe.
mybearworld
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

(#24)
Making everything an import is not what I want. I think I am going to make an operator be the constructor for object automatically like $ or % maybe.
Maybe you can do it like Rust?

use std::env;

fn main() {
// Now, std::env::args can be used like so:
let args = env::args();

// However, I can also access things from std::fs, even if I have not used it,
// by fully qualifying:
std::fs::write("foo.txt", "bar").unwrap();
}

Last edited by mybearworld (Oct. 11, 2023 13:44:50)

ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

mybearworld wrote:

Maybe you can do it like Rust?

use std::env;

fn main() {
// Now, std::env::args can be used like so:
let args = env::args();

// However, I can also access things from std::fs, even if I have not used it,
// by fully qualifying:
std::fs::write("foo.txt", "bar").unwrap();
}
I'm personally not a big fan of Rust's implicit imports You should be able to know what a program uses if you just look at the top of a file
mybearworld
Scratcher
1000+ posts

Custom Programming Languages

ajskateboarder wrote:

(#26)
I'm personally not a big fan of Rust's implicit imports You should be able to know what a program uses if you just look at the top of a file
You can still see what crates are being used in the Cargo.toml file. Details of which specific functions/structs/enums/etc are being used shouldn't be important if the crate is well designed (e.g. if every module serves one purpose).
__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

mybearworld wrote:

__Falcon-Games__ wrote:

(#24)
Making everything an import is not what I want. I think I am going to make an operator be the constructor for object automatically like $ or % maybe.
Maybe you can do it like Rust?

use std::env;

fn main() {
// Now, std::env::args can be used like so:
let args = env::args();

// However, I can also access things from std::fs, even if I have not used it,
// by fully qualifying:
std::fs::write("foo.txt", "bar").unwrap();
}
Yeah no. So I have thought to make $ a short hand for object since it currently has no use.
So $(a=1, b=2, c=3)?
rdococ
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

Yeah no. So I have thought to make $ a short hand for object since it currently has no use.
So $(a=1, b=2, c=3)?
If you're not using square brackets for anything, how about [a=1, b=2, c=3]?

Last edited by rdococ (Oct. 11, 2023 18:45:17)

__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

rdococ wrote:

__Falcon-Games__ wrote:

Yeah no. So I have thought to make $ a short hand for object since it currently has no use.
So $(a=1, b=2, c=3)?
If you're not using square brackets for anything, how about [a=1, b=2, c=3]?
That is genius.
ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

rdococ wrote:

__Falcon-Games__ wrote:

Yeah no. So I have thought to make $ a short hand for object since it currently has no use.
So $(a=1, b=2, c=3)?
If you're not using square brackets for anything, how about [a=1, b=2, c=3]?
That is genius.
What would you do for lists?
mybearworld
Scratcher
1000+ posts

Custom Programming Languages

ajskateboarder wrote:

(#31)

__Falcon-Games__ wrote:

rdococ wrote:

__Falcon-Games__ wrote:

Yeah no. So I have thought to make $ a short hand for object since it currently has no use.
So $(a=1, b=2, c=3)?
If you're not using square brackets for anything, how about [a=1, b=2, c=3]?
That is genius.
What would you do for lists?
Maybe just [1, 2, 3]? Also, I probably missed something, is there any reason objects can't just be {a=1, b=2, c=3}?
__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

mybearworld wrote:

ajskateboarder wrote:

(#31)

__Falcon-Games__ wrote:

rdococ wrote:

__Falcon-Games__ wrote:

Yeah no. So I have thought to make $ a short hand for object since it currently has no use.
So $(a=1, b=2, c=3)?
If you're not using square brackets for anything, how about [a=1, b=2, c=3]?
That is genius.
What would you do for lists?
Maybe just [1, 2, 3]? Also, I probably missed something, is there any reason objects can't just be {a=1, b=2, c=3}?
Because of callbacks.
mybearworld
Scratcher
1000+ posts

Custom Programming Languages

What do callbacks have to do with this?
__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

Because the syntax of a callback is…
import Console

fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

mybearworld wrote:

What do callbacks have to do with this?
The language probably uses braces for callbacks already, so it would hard to differentiate, to some degree
NFlex23
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

Because the syntax of a callback is…
import Console

fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
So a callback is just an anonymous function? Any reason you aren't using `fn() { … }`?
__Falcon-Games__
Scratcher
1000+ posts

Custom Programming Languages

NFlex23 wrote:

__Falcon-Games__ wrote:

Because the syntax of a callback is…
import Console

fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
So a callback is just an anonymous function? Any reason you aren't using `fn() { … }`?
Because that's weird and annoying. I also just like { … } over fn() { … }.
NFlex23
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

NFlex23 wrote:

__Falcon-Games__ wrote:

Because the syntax of a callback is…
import Console

fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
So a callback is just an anonymous function? Any reason you aren't using `fn() { … }`?
Because that's weird and annoying. I also just like { … } over fn() { … }.
While it may be faster to type, I think your syntax may be a bit more confusing since you already have `fn x() { … }` for defining functions, and `{…}` is typically used for objects/records/arrays in most other languages. Also, how would you denote parameters in the function?

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

ajskateboarder
Scratcher
1000+ posts

Custom Programming Languages

__Falcon-Games__ wrote:

NFlex23 wrote:

__Falcon-Games__ wrote:

Because the syntax of a callback is…
import Console

fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
So a callback is just an anonymous function? Any reason you aren't using `fn() { … }`?
Because that's weird and annoying. I also just like { … } over fn() { … }.
Wait so how would you supply arguments to the anonymous function if it's just a block? Would you do:
((x, y){Console.out(x + y)})(12, 1)
Or something like that?

Powered by DjangoBB