Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)
- 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.
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)
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.
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!
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)These blocks were especially easy to obtain back when the Add to backpack block was a thing
set [reported value v] to ((a) + (b))
(join (letter (0) of {add (1) and (2)}) (reported value))
- TheCreatorOfUnTV
-
Scratcher
1000+ posts
Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)
Ah, I see. Thanks!I don't think that was possible.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)These blocks were especially easy to obtain back when the Add to backpack block was a thing
set [reported value v] to ((a) + (b))
(join (letter (0) of {add (1) and (2)}) (reported value))
- dynamicsofscratch
-
Scratcher
1000+ posts
Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)
(#1)Scratch is an procedural language like C. Functional programming is possible with Scratch using the My Blocks section to create unique functions.
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.
- Jonathan50
-
Scratcher
1000+ posts
Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)
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)
(#24)It is possible, but it doesn't actually work because “processed value” is calculated before the custom block gets called.
I don't think that was possible.
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)
…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)
(#28)I think now my understanding of FP and your understanding of FP is different.…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)
- Discussion Forums
- » Advanced Topics
-
» Is Scratch procedural, object-oriented, functional or some kind of combination? (CS50)






