Discuss Scratch
- __Falcon-Games__
-
1000+ posts
Custom Programming Languages
It will pass the variables on the current scope as arguments to the function which has been expanded.Interesting… what does the ‘summary = expand(summary)’ line do? -snip-
It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?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? 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
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.Could this be a bit easier? (for example, calling `object` instead of `Standard.Object`) 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
- rdococ
-
1000+ posts
Custom Programming Languages
Huh… I take it your functions don't capture variables from their scope automatically? It will pass the variables on the current scope as arguments to the function which has been expanded.
How about `Std.Object`, based on the C++ syntax for namespaces, `std::`? It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?
- ajskateboarder
-
1000+ posts
Custom Programming Languages
Maybe move “Object” and other datatypes into a seperate library that you specifically import? Like “import Object from Datatypes”It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?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? So to create an object in Sandwich you don't need to create classes first, here's how you do it.
snip
- __Falcon-Games__
-
1000+ posts
Custom Programming Languages
Not their parent scope, the object. If you mean the object's scope then yes.Huh… I take it your functions don't capture variables from their scope automatically? It will pass the variables on the current scope as arguments to the function which has been expanded.
How about `Std.Object`, based on the C++ syntax for namespaces, `std::`? It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?
That could work but still kinda lengthy.
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 move “Object” and other datatypes into a seperate library that you specifically import? Like “import Object from Datatypes”It is verbose but it makes the most sense and is the easiest to parse, could you suggest any alternatives?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? So to create an object in Sandwich you don't need to create classes first, here's how you do it.
snip
- mybearworld
-
1000+ posts
Custom Programming Languages
(#24)Maybe you can do it like Rust?
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.
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
-
1000+ posts
Custom Programming Languages
I'm personally not a big fan of Rust's implicit imports 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();
}

- mybearworld
-
1000+ posts
Custom Programming Languages
(#26)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).
I'm personally not a big fan of Rust's implicit importsYou should be able to know what a program uses if you just look at the top of a file
- __Falcon-Games__
-
1000+ posts
Custom Programming Languages
Yeah no. So I have thought to make $ a short hand for object since it currently has no use.(#24)Maybe you can do it like Rust?
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.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();
}
So $(a=1, b=2, c=3)?
- rdococ
-
1000+ posts
Custom Programming Languages
If you're not using square brackets for anything, how about [a=1, b=2, c=3]? 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)?
Last edited by rdococ (Oct. 11, 2023 18:45:17)
- __Falcon-Games__
-
1000+ posts
Custom Programming Languages
That is genius.If you're not using square brackets for anything, how about [a=1, b=2, c=3]? 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)?
- ajskateboarder
-
1000+ posts
Custom Programming Languages
What would you do for lists?That is genius.If you're not using square brackets for anything, how about [a=1, b=2, c=3]? 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)?
- mybearworld
-
1000+ posts
Custom Programming Languages
(#31)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}?What would you do for lists?That is genius.If you're not using square brackets for anything, how about [a=1, b=2, c=3]? 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)?
- __Falcon-Games__
-
1000+ posts
Custom Programming Languages
Because of callbacks.(#31)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}?What would you do for lists?That is genius.If you're not using square brackets for anything, how about [a=1, b=2, c=3]? 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)?
- mybearworld
-
1000+ posts
Custom Programming Languages
What do callbacks have to do with this?
- __Falcon-Games__
-
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
-
1000+ posts
Custom Programming Languages
The language probably uses braces for callbacks already, so it would hard to differentiate, to some degree What do callbacks have to do with this?
- NFlex23
-
1000+ posts
Custom Programming Languages
So a callback is just an anonymous function? Any reason you aren't using `fn() { … }`? Because the syntax of a callback is…import Console
fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
- __Falcon-Games__
-
1000+ posts
Custom Programming Languages
Because that's weird and annoying. I also just like { … } over fn() { … }.So a callback is just an anonymous function? Any reason you aren't using `fn() { … }`? Because the syntax of a callback is…import Console
fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
- NFlex23
-
1000+ posts
Custom Programming Languages
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?Because that's weird and annoying. I also just like { … } over fn() { … }.So a callback is just an anonymous function? Any reason you aren't using `fn() { … }`? Because the syntax of a callback is…import Console
fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
Last edited by NFlex23 (Oct. 12, 2023 13:26:12)
- ajskateboarder
-
1000+ posts
Custom Programming Languages
Wait so how would you supply arguments to the anonymous function if it's just a block? Would you do:Because that's weird and annoying. I also just like { … } over fn() { … }.So a callback is just an anonymous function? Any reason you aren't using `fn() { … }`? Because the syntax of a callback is…import Console
fun main() {
// Create a callback and run it.
{
Console.out("Hello, world!")
}()
}
((x, y){Console.out(x + y)})(12, 1)