Discuss Scratch

  • Discussion Forums
  • » Advanced Topics
  • » If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null? [RSS Feed]
bobbybee
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

define add (x) (y)
replace item (1) of [return v] with ((x) + (y))

(pick random (1) to (item ((add (1) (1)::stack) + (1)) of [return v]))

Last edited by bobbybee (May 9, 2016 22:29:52)

Jonathan50
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

Well, it should be… I think I tried that before and it worked then reported “NULL” or something.
bobbybee
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

Jonathan50 wrote:

Well, it should be… I think I tried that before and it worked then reported “NULL” or something.
Alright. Then name the list “NULL” and use the reporter value as the return register list name

Could be cute if not useful?
adespotist
New Scratcher
95 posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

bobbybee wrote:

Jonathan50 wrote:

Well, it should be… I think I tried that before and it worked then reported “NULL” or something.
Alright. Then name the list “NULL” and use the reporter value as the return register list name

Could be cute if not useful?
Right now I'm working on something else, but does it work? I could use it for my eventual Snap!-to-Scratch transpiler.
bobbybee
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

adespotist wrote:

bobbybee wrote:

Jonathan50 wrote:

Well, it should be… I think I tried that before and it worked then reported “NULL” or something.
Alright. Then name the list “NULL” and use the reporter value as the return register list name

Could be cute if not useful?
Right now I'm working on something else, but does it work? I could use it for my eventual Snap!-to-Scratch transpiler.
Haven't tried it, I'm working on my Lisp->Scratch compiler
liam48D
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

https://scratch.mit.edu/projects/108953360/

EDIT: for anybody who's on a mobile device, see the script and the output.

EDIT2: for Gingerline 2.0 or any other backwards-compatible mod, is this true?


(scratchblocks)

Last edited by liam48D (May 10, 2016 10:40:40)

bobbybee
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

liam48D wrote:

https://scratch.mit.edu/projects/108953360/

EDIT: for anybody who's on a mobile device, see the script and the output.

EDIT2: for Gingerline 2.0 or any other backwards-compatible mod, is this true?


(scratchblocks)
Wait, so I invented custom reporters? Cool!
bobbybee
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

I have a few ideas for performance improvements once I'm on a machine with Flash. Namely, cutting out the addition…..
liam48D
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

bobbybee wrote:

liam48D wrote:

https://scratch.mit.edu/projects/108953360/

EDIT: for anybody who's on a mobile device, see the script and the output.

EDIT2: for Gingerline 2.0 or any other backwards-compatible mod, is this true?


(scratchblocks)
Wait, so I invented custom reporters? Cool!
..yep


bobbybee
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

liam48D wrote:

..yep

So, think I should not do Chimera and just go with this instead for Scratch Day? ^_^
liam48D
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

bobbybee wrote:

liam48D wrote:

..yep

So, think I should not do Chimera and just go with this instead for Scratch Day? ^_^
..nah, bring Chimera too, but this is important
PullJosh
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

That's actually really clever!
MegaApuTurkUltra
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

PullJosh wrote:

That's actually really clever!
^

Very late edit: I just realized the potential this has for tremendous abuse. For example, you could make (faster?) if-elses by abusing short circuiting of the and/or blocks. Or automatic stack handling with something like
(join(item [last v] of {my block::custom}){delete [last v] of [null v]})

Last edited by MegaApuTurkUltra (May 10, 2016 16:28:44)

bobbybee
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

MegaApuTurkUltra wrote:

PullJosh wrote:

That's actually really clever!
^

Very late edit: I just realized the potential this has for tremendous abuse. For example, you could make (faster?) if-elses by abusing short circuiting of the and/or blocks. Or automatic stack handling with something like
(join(item [last v] of {my block::custom}){delete [last v] of [null v]})
That's beautiful.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

Yay! However, if a number is added to null rather than 0, what will the output be? Let me check that.

EDIT: Yup, it still works.

Last edited by gdpr533f604550b2f20900645890 (May 10, 2016 19:39:20)

NoMod-Programming
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

bobbybee wrote:

MegaApuTurkUltra wrote:

PullJosh wrote:

That's actually really clever!
^

Very late edit: I just realized the potential this has for tremendous abuse. For example, you could make (faster?) if-elses by abusing short circuiting of the and/or blocks. Or automatic stack handling with something like
(join(item [last v] of {my block::custom}){delete [last v] of [null v]})
That's beautiful.
WOAH!
-Io-
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

It doesn't work as you may expect

It actually gets the value returned from the block (null) and then it runs the block
You can see in liam's project the say block actually says the last value instead of the current one.

btw i tested with
(join (letter (0) of ({custom reporter :: custom} + (1))) (item ({custom reporter :: custom} + (1)) of [return v]))
to see if reporters run each block one by one. I expected to run the first block (the functional one), then run the second block (the non-functional one) to get the value returned from the first one, but no it didn't work
liam48D
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

-Io- wrote:

It doesn't work as you may expect

It actually gets the value returned from the block (null) and then it runs the block
You can see in liam's project the say block actually says the last value instead of the current one.

btw i tested with
(join (letter (0) of ({custom reporter :: custom} + (1))) (item ({custom reporter :: custom} + (1)) of [return v]))
to see if reporters run each block one by one. I expected to run the first block (the functional one), then run the second block (the non-functional one) to get the value returned from the first one, but no it didn't work
Argh, noooooes.
bobbybee
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

-Io- wrote:

It doesn't work as you may expect

It actually gets the value returned from the block (null) and then it runs the block
You can see in liam's project the say block actually says the last value instead of the current one.

btw i tested with
(join (letter (0) of ({custom reporter :: custom} + (1))) (item ({custom reporter :: custom} + (1)) of [return v]))
to see if reporters run each block one by one. I expected to run the first block (the functional one), then run the second block (the non-functional one) to get the value returned from the first one, but no it didn't work
I'm not sure I understand the problem. Can you explain a bit more what happened vs what you expected? Perhaps it can be mitigated cleverly.
BookOwl
Scratcher
1000+ posts

If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null?

Wow!
  • Discussion Forums
  • » Advanced Topics
  • » If I stuff a `call` primitive where a reporter should go, will the procedure still be executed with side effects and simply return zero/null? [RSS Feed]

Powered by DjangoBB