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.

Try out Noml!
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.

Try out Noml!
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)


Signatures are the only place where assets links still work.
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).

Signatures are the only place where assets links still work.
__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)?

Try out Noml!
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.

Try out Noml!
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}?

Signatures are the only place where assets links still work.
__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.

Try out Noml!
mybearworld
Scratcher
1000+ posts

Custom Programming Languages

What do callbacks have to do with this?

Signatures are the only place where assets links still work.
__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!")
}()
}

Try out Noml!
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() { … }`?

Help improve the Advanced Topics (Really!)
Before you create a topic:
Always search for duplicates or other similar topics before making an umbrella topic, e.g., “The Mac Topic”.
  • Is it about something you are planning on making but haven't made yet? If so, please wait to post until you have created a working prototype. This is a key factor to keeping the ATs as clean as possible.
  • The ATs aren't technical support. It is perfectly valid to ask questions about things related to programming, but not issues with external websites, apps, or devices. Most sites have their own support system; try asking there!
  • Is it related to something you are making in Scratch? (This includes OSes and other Scratch projects) If so, please post in Collaboration, Show and Tell, or another similar forum.
  • Is your topic questionably “advanced”? Try browsing the other forums to see if your topic fits better in one of those.
  • Issues with Scratch itself should be put in Bugs and Glitches.
Before you post: Is what you're posting likely to start an argument or derail the thread (e.g., browsers, operating systems)? If so, please re-think your post!





__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() { … }.

Try out Noml!
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)


Help improve the Advanced Topics (Really!)
Before you create a topic:
Always search for duplicates or other similar topics before making an umbrella topic, e.g., “The Mac Topic”.
  • Is it about something you are planning on making but haven't made yet? If so, please wait to post until you have created a working prototype. This is a key factor to keeping the ATs as clean as possible.
  • The ATs aren't technical support. It is perfectly valid to ask questions about things related to programming, but not issues with external websites, apps, or devices. Most sites have their own support system; try asking there!
  • Is it related to something you are making in Scratch? (This includes OSes and other Scratch projects) If so, please post in Collaboration, Show and Tell, or another similar forum.
  • Is your topic questionably “advanced”? Try browsing the other forums to see if your topic fits better in one of those.
  • Issues with Scratch itself should be put in Bugs and Glitches.
Before you post: Is what you're posting likely to start an argument or derail the thread (e.g., browsers, operating systems)? If so, please re-think your post!





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