Discuss Scratch

Stegie1234
Scratcher
100+ posts

Is Scratch statically or dynamically typed?

Scratch variables can’t change to lists while the project is running, does that mean Scratch is statically typed? Or dynamically typed, since the variables can be a string, int, or float at any time?

Last edited by Stegie1234 (Sept. 18, 2023 23:33:49)

Clippy-Cat
Scratcher
66 posts

Is Scratch statically or dynamically typed?

Scratch is dynamically typed. Although it does have some strict-ish elements, this does not make it strictly typed.

In fact, Scratch is more dynamically typed than most other dynamically typed languages, as there's no difference between a number and a string within Scratch's internal logic.

Last edited by Clippy-Cat (Sept. 19, 2023 01:09:06)

DifferentDance8
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

A little bit of both.
donotforgetmycode
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

Scratch is dynamically typed. The reason variables can't change to lists is because lists aren't a data type in Scratch.
EngineerRunner
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

dynamically. hell, you can do this:
if (item <(apple) = (other list::list)> of [list v]) then
say <not(item (3) of [other other list v]::list)>
end

Last edited by EngineerRunner (Sept. 20, 2023 15:48:16)

ajskateboarder
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

It's neither; it has no type system so you can't validate data or check the type of a variable

You'll need to check for things that make a certain type manually

donotforgetmycode
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

ajskateboarder wrote:

It's neither; it has no type system so you can't validate data or check the type of a variable

You'll need to check for things that make a certain type manually


It actually does have a type system.
ajskateboarder
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

donotforgetmycode wrote:

ajskateboarder wrote:

It's neither; it has no type system so you can't validate data or check the type of a variable

You'll need to check for things that make a certain type manually


It actually does have a type system.
Example?
CST1229
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

ajskateboarder wrote:

(#8)
Example?
Number-type values get slightly visually rounded in variable monitors (but strings don't). However, most blocks cast values to a certain type so they all behave the same in most other cases.


(EDIT: It's not caused by floating-point inaccuracies, as if you put it in a join block it stays precise:)

Last edited by CST1229 (Sept. 20, 2023 19:45:37)

donotforgetmycode
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

ajskateboarder wrote:

Example?
Make a sprite with 2 costumes. The first costume should be called something like “costume1” and the second costume should be called “1”. Now run these two blocks:
switch costume to (join [1] [])

switch costume to ((1) + ())
Stegie1234
Scratcher
100+ posts

Is Scratch statically or dynamically typed?

donotforgetmycode wrote:

lists aren't a data type in Scratch.
What? Arrays aren’t a data type the variables can be, but they still exist in Scratch.

ajskateboarder wrote:

It's neither; it has no type system so you can't validate data or check the type of a variable
How do you know it doesn’t have a type system? It could have types, but you can’t check the type of a variable because
<[] = []>
is ==, not ===, in JavaScript.

EngineerRunner wrote:

dynamically. hell, you can do this:
if (item <(apple) = (other list::list)> of [list v]) then
say <not(item (3) of [other other list v]::list)>
end
1. You can do that in most statically typed languages.
2. Scratch doesn’t allow variables or list items to be in an if statement.
Edit: list items can be used a booleans.

Last edited by Stegie1234 (Sept. 21, 2023 05:48:37)

ajskateboarder
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

Stegie1234 wrote:

donotforgetmycode wrote:

lists aren't a data type in Scratch.
What? Arrays aren’t a data type the variables can be, but they still exist in Scratch.

ajskateboarder wrote:

It's neither; it has no type system so you can't validate data or check the type of a variable
How do you know it doesn’t have a type system? It could have types, but you can’t check the type of a variable because
<[] = []>
is ==, not ===, in JavaScript.
So it doesn't have a type system

Also IDK I don't think most other dynamic langs let you do this

CST1229
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

Stegie1234 wrote:

(#11)
2. Scratch doesn’t allow variables or list items to be in an if statement.
Likely due to a mistake, 2 specific list blocks can be put into boolean inputs:
donotforgetmycode
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

ajskateboarder wrote:

So it doesn't have a type system
Yes it does, see my post above.
ajskateboarder
Scratcher
1000+ posts

Is Scratch statically or dynamically typed?

donotforgetmycode wrote:

ajskateboarder wrote:

So it doesn't have a type system
Yes it does, see my post above.
Yeah I saw that, but in the sense of a traditional type system:



It doesn't have one, by definition. Implicit type casting doesn't really make a type system, it has to have a proper distinction

Powered by DjangoBB