Discuss Scratch

TheAspiringHacker
Scratcher
100+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

IIRC sprites and broadcasts come from Scratch's Smalltalk heritage. However, sprites mix up state and graphics (an object doesn't have anything to do with the screen). Also, Smalltalk messages aren't concurrent like broadcasts, right? Scratch broadcasts can't even take arguments or return values.

I second ElsieBreeze's examples of the ML dialects SML and OCaml for FP. Snap! is a Scratch-like functional language, and it is different from SML and OCaml. The ML dialects emphasize types, while Snap! does not.
Jonathan50
Scratcher
1000+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

Sheep_maker wrote:

But aren't broadcasts and clone inheritance Scratch features? Or do you mean that they aren't intended to be used for message passing and inheritance?
Messages in OOP are different from broadcasts because they're sent to individual objects, which may be arbitrary, may have arguments, and can be used recursively, and methods can return values. Each clone of a sprite has the same set of local variables and scripts. Analogously, although Scratch doesn't allow you to make a reporter, the same effect can be achieved by making a custom block which stores its result in a variable.

TheAspiringHacker wrote:

IIRC sprites and broadcasts come from Scratch's Smalltalk heritage. However, sprites mix up state and graphics (an object doesn't have anything to do with the screen). Also, Smalltalk messages aren't concurrent like broadcasts, right? Scratch broadcasts can't even take arguments or return values.
Scratch initially had procedures, and a sprite could invoke a procedure in another sprite, but the receiver would be hard-coded (it couldn't be the value of an arbitrary expression.) David Feinberg invented broadcasts, which eventually replaced procedures: http://llk.media.mit.edu/papers/davefthesis.pdf (They were somewhat more general at the time.)

Last edited by Jonathan50 (May 3, 2020 01:10:39)

Sheep_maker
Scratcher
1000+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

Ah, I see. Thanks!

Jonathan50 wrote:

Analogously, although Scratch doesn't allow you to make a reporter, the same effect can be achieved by making a custom block which stores its result in a variable.
In Scratch 2.0, custom reporters were possible-ish with hacked blocks:
define add (a) and (b)
set [reported value v] to ((a) + (b))
(join (letter (0) of {add (1) and (2)}) (reported value))
These blocks were especially easy to obtain back when the Add to backpack block was a thing
TheCreatorOfUnTV
Scratcher
1000+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

Sheep_maker wrote:

Ah, I see. Thanks!

Jonathan50 wrote:

Analogously, although Scratch doesn't allow you to make a reporter, the same effect can be achieved by making a custom block which stores its result in a variable.
In Scratch 2.0, custom reporters were possible-ish with hacked blocks:
define add (a) and (b)
set [reported value v] to ((a) + (b))
(join (letter (0) of {add (1) and (2)}) (reported value))
These blocks were especially easy to obtain back when the Add to backpack block was a thing
I don't think that was possible.
dynamicsofscratch
Scratcher
1000+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

emma2o2o wrote:

(#1)
Hi there,

I'm curious!

Is Scratch procedural (like C), object-oriented (like JavaScript), functional (like Python) or some kind of combination?

Many thanks,
Emma.
Scratch is an procedural language like C. Functional programming is possible with Scratch using the My Blocks section to create unique functions.
Jonathan50
Scratcher
1000+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

TheCreatorOfUnTV wrote:

I don't think that was possible.
It definitely was. You can try it with the Scratch 2 offline editor if you want (unzip SB2 and edit project.json). But please don't necropost on years-old topics, without a really good reason.
mybearworld
Scratcher
1000+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

TheCreatorOfUnTV wrote:

(#24)
I don't think that was possible.
It is possible, but it doesn't actually work because “processed value” is calculated before the custom block gets called.
https://mybearworld.github.io/sfi?sb2-custom-reporters.png
gilbert_given_189
Scratcher
1000+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

dynamicsofscratch wrote:

…Functional programming is possible with Scratch using the My Blocks section to create unique functions.
Scratch doesn't allow inputting functions as arguments to functions, which is a pretty major—no, defining characteristic of functional programming. You can't easily do this on Scratch:

// try defining this function!
define get derivative of (f) at (x)
set [dx v] to (0.00001)
return (((apply (f) ((x) + (dx)) :: custom) - (apply (f) (x) :: custom)) / (dx)) :: custom

when green flag clicked
say (get derivative of (function of (x :: custom-arg) is ([sqrt v] of (x :: custom-arg)) :: custom) at (2) :: custom) for (2) secs
say (get derivative of (function of (x :: custom-arg) is ([sin v] of (x :: custom-arg)) :: custom) at (270) :: custom) for (2) secs

Or maybe my definition of FP is different than others. (like that time)

Last edited by gilbert_given_189 (July 12, 2024 14:53:16)

dynamicsofscratch
Scratcher
1000+ posts

Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)

gilbert_given_189 wrote:

(#28)

dynamicsofscratch wrote:

…Functional programming is possible with Scratch using the My Blocks section to create unique functions.
Scratch doesn't allow inputting functions as arguments to functions, which is a pretty major—no, defining characteristic of functional programming. You can't easily do this on Scratch:

// try defining this function!
define get derivative of (f) at (x)
set [dx v] to (0.00001)
return (((apply (f) ((x) + (dx)) :: custom) - (apply (f) (x) :: custom)) / (dx)) :: custom

when green flag clicked
say (get derivative of (function of (x :: custom-arg) is ([sqrt v] of (x :: custom-arg)) :: custom) at (2) :: custom) for (2) secs
say (get derivative of (function of (x :: custom-arg) is ([sin v] of (x :: custom-arg)) :: custom) at (270) :: custom) for (2) secs

Or maybe my definition of FP is different than others. (like that time)

I think now my understanding of FP and your understanding of FP is different.

Powered by DjangoBB