Discuss Scratch

Greg8128
Scratcher
500+ posts

Lambda functions

Lambda functions are a type of variable (possibly a special type of variable). They take one input and return one output. (You can chain a lambda function to
(lambda (x) . () ::operators) // Lambda function with one argument
(() of ()::operators) // Apply a lambda function

An example of how this could be used:
set [fun v] to (lambda (x) . (lambda (y) . (((x) * (2)) + (y)) ::operators) ::operators)
say (((fun) of (20) ::operators) of (2)::operators) // 42
Other uses of lambda functions include:
(lambda (x) . (item (x) of [list v]) ::operators) // Specify a list for a function to access
(lambda (x) . (lambda (y) . <(x) > (y)> ::operators) ::operators) // Comparator for list sorting blocks
(lambda (fst) . (lambda (snd) . (lambda (i) . (if <(i) = (0)> then (fst) else (snd) ::operators) ::operators) ::operators) ::operators) // Make pairs of variables

Bonus blocks: highly useful but can theoretically be re-implemented using the first blocks
(if () then () else () ::operators) // Not needed if lazy evaluation is available
(fix () :: operators) // Fixed point combinator, useful for making recursive anonymous functions
ScratchCat1038
Scratcher
1000+ posts

Lambda functions

No Support. Scratch is supposed to be an introduction to programming, and this is way too complex for that.
Greg8128
Scratcher
500+ posts

Lambda functions

ScratchCat1038 wrote:

No Support. Scratch is supposed to be an introduction to programming, and this is way too complex for that.
Yes, and this is a good introduction to lambda functions (and how they can be extremely useful)
fdreerf
Scratcher
1000+ posts

Lambda functions

Greg8128 wrote:

ScratchCat1038 wrote:

No Support. Scratch is supposed to be an introduction to programming, and this is way too complex for that.
Yes, and this is a good introduction to lambda functions (and how they can be extremely useful)
I don't see any usefulness or how it is a good introduction. I have no clue what this block does, I just see a bunch of lambda blocks with some variables, and it also makes computer scientists look like deranged mathematicians who probably would have committed first-degree murder had we not stuffed filing cabinets with electric parts to distract them.
sealifefriend
Scratcher
500+ posts

Lambda functions

I don't even understand that (not that I understand most code…) so a new scratcher definitely wouldn't.
PkmnQ
Scratcher
1000+ posts

Lambda functions

I think there should be more indication that those blocks go together. Maybe they'd be in their own extension?
Greg8128
Scratcher
500+ posts

Lambda functions

PkmnQ wrote:

I think there should be more indication that those blocks go together. Maybe they'd be in their own extension?
Good idea! Maybe “custom blocks” for everything except
(if <> then () else () ::operators)
PkmnQ
Scratcher
1000+ posts

Lambda functions

Bump,
(lambda (x :: custom-arg) -> () :: custom-arg)
(apply lambda () to () :: custom-arg)
cookieclickerer33
Scratcher
1000+ posts

Lambda functions

This is a feature in snap! But no support because I don’t understand it at all
ajskateboarder
Scratcher
1000+ posts

Lambda functions

Why is greg such a functional programming nerd XD

cookieclickerer33 wrote:

This is a feature in snap! But no support because I don’t understand it at all
It's not about how a single person understands it, but how it will eventually teach people about such concepts in more advanced programming.

Support if it were an extension. Define blocks are a little clunky when you want to do a few small tasks.
PkmnQ
Scratcher
1000+ posts

Lambda functions

My only issue is how they would work as strings. Does it just do something like (lambda)? Can you just not put them there? If so, how do variables work? Do we have to make a new kind of lambda variable?
Crow_Boy08
Scratcher
1000+ posts

Lambda functions

what about da lamb?







Lamb




















No
TheSecondGilbert
Scratcher
100+ posts

Lambda functions

As I see it, this would only complicate Scratch. On a language where all datatypes are strictly a string, it would be a hassle for the devs to add another type. I mean, how would you represent this?
((lambda (x :: custom-arg) . () :: custom-arg) + (1))
(letter (1) of (lambda (x :: custom-arg) . () :: custom-arg))
((join [foo] [bar]) on (2) :: custom-arg)
I'd admit, lambda functions are cool, but not on a language like Scratch. It makes sense in Snap! because variables could be on many datatypes, not just strings.
PkmnQ
Scratcher
1000+ posts

Lambda functions

PkmnQ wrote:

My only issue is how they would work as strings. Does it just do something like (lambda)? Can you just not put them there? If so, how do variables work? Do we have to make a new kind of lambda variable?
Oh, actually, wait a minute.

Blank strings. Try to apply a number to something else? Get a blank string. Try to take the first letter of a lambda? Blank string. Try to add 1 to a lambda? 1. Because the lambda is a blank string.
TheSecondGilbert
Scratcher
100+ posts

Lambda functions

bump
cookieclickerer33
Scratcher
1000+ posts

Lambda functions

I return to this suggestion now that I have used snap extensively

Please I need this now..
Custom reporters, so many possibilities
rdococ
Scratcher
1000+ posts

Lambda functions

Ya see, Scratch is a programming language for kids to express their creativity, through creating games, stories, animations, etc. It's easy to pick up, you can do a lot of things with it and you can get quite advanced. It is also a stepping stone to more advanced forms of programming.

Lambda functions (i.e. functions as values, not just regular custom reporters) don't particularly help Scratchers create games, stories and animations, at least not in ways that broadcasts don't already do. They're not particularly easy to pick up (Snap! has done a respectable job of it, but for an older audience as part of a college curriculum) and only really aid with advanced projects and as a stepping stone.

IMO, a better idea for this kind of thing is a more advanced block-based language with an object-oriented model, but it would have to be wholly separate from Scratch.

Last edited by rdococ (March 16, 2023 12:48:12)

ajskateboarder
Scratcher
1000+ posts

Lambda functions

rdococ wrote:

IMO, a better idea for this kind of thing is a more advanced block-based language with an object-oriented model, but it would have to be wholly separate from Scratch.
Maybe it could be part of that Smalltalk rewrite you propose :D
blablablahello
Scratcher
1000+ posts

Lambda functions

Personally I… still dont udnerstand how this thing works

like it sounds just like any other function in any other programming language, but I dont see it being defined so I have absolutely no idea how this should/would work

searched it up and now I understand this way more clearly

its literally just a variable defined as a function

so its literally just a function variable (like a more easily changeable function or something)

I believe https://www.w3schools.com/python/python_lambda.asp explains this better lol
ajskateboarder
Scratcher
1000+ posts

Lambda functions

blablablahello wrote:

its literally just a variable defined as a function
The point of introducing this feature is to be able to pass around functions to other functions. This way, you can create modular logic which is somewhat easier to maintain than if you were using plain variables/functions.

TBH, pure functional programmers seem to be in the minority these days

Powered by DjangoBB