Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous Functions #15

Open
bbrk24 opened this issue Oct 29, 2021 · 11 comments
Open

Anonymous Functions #15

bbrk24 opened this issue Oct 29, 2021 · 11 comments
Labels
IDEA IDEA ON IMPROVING THE LANG

Comments

@bbrk24
Copy link

bbrk24 commented Oct 29, 2021

I was messing around with callbacks, and I noticed something interesting:

G'DAY MATE!

IMPOHT ME FUNC HitTheSack;

THE HARD YAKKA FOR performAfter IS (callback, duration) <
    HitTheSack(duration);
    callback();
>

THE HARD YAKKA FOR helloWorld IS () <
    GIMME "Hello, World!";
>

I RECKON duration = 1000;

// What combinations of literal/variable are legal?
performAfter(helloWorld, 1000); // works
performAfter(helloWorld, duration); // works
performAfter(// wait, do function literals/closures even exist?
    1000);

CHEERS C***!

I don't have any ideas for what they would be called, but I'm not even sure words would be necessary -- they tend to be pretty punctuationful. Consider how the NOP lambda is []() { } in C++ and () => {} in JS.

Syntactically, I perfer how Swift and Ruby handle it, where the entire closure body is wrapped in braces (in contrast with the closure syntax in JS, which consists of multiple separate parts).

@bbrk24
Copy link
Author

bbrk24 commented Oct 29, 2021

Relatedly, this is legal:

G'DAY MATE!

THE HARD YAKKA FOR func1 IS () <
    GIMME "func1 called";
>

THE HARD YAKKA FOR func2 IS () <
    GIMME "func2 called";
>

func1 = func2;
func1(); // prints "func2 called"

CHEERS C***!

I'd think only variables declared with I RECKON should be mutable, and not ones declared with THE HARD YAKKA FOR ... IS.

@jwfxpr
Copy link
Contributor

jwfxpr commented Oct 29, 2021

When I think of Australianisms for when you don't know, or don't want to use, a name, what stands out to me is "old mate"

How about

performAfter(OLD MATE () IS < GIMME "Oi mate"; GIMME "Clear off"; >, 1000);

@bbrk24
Copy link
Author

bbrk24 commented Oct 29, 2021

I'm not qualified to comment on the Australianism, but the syntax looks fine (and is reminiscent of older JS function() {}).

@jwfxpr
Copy link
Contributor

jwfxpr commented Oct 29, 2021

I'd think only variables declared with I RECKON should be mutable, and not ones declared with THE HARD YAKKA FOR ... IS.

In addition to this, it would be nice to be able to declare an immutable variable. DEADSET?

I RECKON x = 1; // Mutable
I DEADSET RECKON y = 2; // Immutable

@zackradisic zackradisic added the IDEA IDEA ON IMPROVING THE LANG label Oct 29, 2021
@bbrk24
Copy link
Author

bbrk24 commented Oct 30, 2021

@jwfxpr I asked someone who is more qualified to speak to the Australianisms than I am, and he basically said that: OLD MATE is fine; DEADSET feels odd there, and if constants are to use RECKON at all, then I FULLY RECKON feels more natural.

@jwfxpr
Copy link
Contributor

jwfxpr commented Oct 30, 2021

Yep @bbrk24 , I FULLY RECKON works too! Looking at it again with fresh eyes, DEADSET seems better to me as a standalone statement, rather than part of I RECKON.

I FULLY RECKON a = 1;
DEADSET b = 2;

Both of those forms seem good to me 😊

@zackradisic
Copy link
Owner

I think I prefer I FULLY RECKON since it sounds more fluent. The lambda function syntax looks good to me!

I can get to work right away on implementing constants and making function declarations immutable.

@bbrk24
Copy link
Author

bbrk24 commented Oct 31, 2021

Before the anonymous functions are fully introduced, I want to point out an inconsistency with the proposed syntax: named functions have IS () < >; anonymous functions have () IS < >.

@zackradisic
Copy link
Owner

@bbrk24 Good point, the finalized syntax will be this then.

OLD MATE IS () < GIMME "Oi mate"; GIMME "Clear off"; >

Also this gave me idea that we should write style rules for the language, things like spacing, conventions, things of that nature

@jwfxpr
Copy link
Contributor

jwfxpr commented Oct 31, 2021

Just so that the examples and discussion here are clear, we've implied (but not discussed) that parameters for old mates go inside the ().

I.e., old mate with no parameters:

OLD MATE IS () < GIMME "Oi mate"; GIMME "Clear off"; >

An old mate with one parameter:

OLD MATE IS (wotareya) < GIMME "Oi " + wotareya; GIMME "Clear off"; >

Old mate with two parameters:

OLD MATE IS (wotareya, yerawanka) < GIMME "Oi " + wotareya; GIMME YA RECKON yerawanka ? < "Bugger off"; > WHATABOUT ? < "Clear off"; > >

etc.

Sidebar q, @zackradisic: I could test this myself, but for the sake of discussion, are YA RECKONs expressions? README.md mentions "if statements", but if we're going to the trouble of implementing lambdas, it seems reasonable that a lambda would be able to use a single YA RECKON to BAIL a value, yes?

@zackradisic
Copy link
Owner

At this moment YA RECKON (if) and YA RECKON ... IS A (match) are statements, so this won't work:

I RECKON x = OLD MATE IS (yerawanka) <  
    BAIL YA RECKON yerawanka ? < "Bugger off"; > WHATABOUT ? < "Clear off"; >;
>(NAH YEAH!);

In retrospect I should have made them expressions, should make that change at some point.

@jwfxpr jwfxpr mentioned this issue Oct 31, 2021
8 tasks
@github-staff github-staff deleted a comment from BenediktMiller Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDEA IDEA ON IMPROVING THE LANG
Projects
None yet
Development

No branches or pull requests

3 participants