New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement anonymous procedure & multi-thread blocks #1565
base: ucr
Are you sure you want to change the base?
Conversation
Amazing! 👍 |
I suggest rename "get global procedure" to "get procedure". |
@ColinTree Rather than having the "get procedure" block take a name parameter, why not provide a dropdown similar to the call blocks? This would allow us to adjust the function reference when the developer renames a procedure. |
Also, because this adds behavior to the companion, the base branch should be |
A name parameter can be called at runtime. |
Computed, maybe? name is a string, and strings are not callable. In any case, all named procedures will be known at compile time, so I think it makes sense to constrain it accordingly in the blocks. |
Sometimes you need to define a series of procedure, the block allows you to decide which one to call based on user input or action. |
You can determine the procedure name that you want to call in runtime, e.g. specified by config from your server during runtime. |
yail can be generated correctly but the variable inside the procedure are not recognised in blockly
TODO: 1. implement parameter defining 2. adapt error detect of anon-procedure define in global var defining
Replaced any "anonymous procedure" with only "procedure" in Msg
@ewpatton Thanks for your reply! In my opinion, avoid programming mistakes should be the responsibility of developers, designers like us should put more focus on adding more and more possibilities & functionalities into the platform/language. But I can see your concern is very reasonable, that many of App Inventor users (developers) are still new for programming. So one solution of this should be adding one more block that has a dropdown of defined procedure names and current existing blocks are still kept for them to choose. What do you think? |
Language designers can't protect developers from logical mistakes, true, but there are certainly plenty of ways in which we can reduce other types of mistakes. For example, this is why some languages have garbage collectors (Java) to prevent memory leaks due to malloc/free mismatches, or memory safety (Rust) to prevent buffer overflow attacks. Look to how variable renaming in App Inventor works as a good example of how we prevent mistakes when it comes to referencing items by name. When you rename a variable, all of its references are renamed at the same time. This doesn't allow one to accidentally decouple the reference from the original definition. I'm simply advocating that we strongly consider that first, and I have given two alternatives approaches that could provide similar flexibility while helping introduce users to the concepts of functional programming in a more guided way. |
Also inviting @jsheldonmit @kdclang @stezelMIT to comment from the educational perspective. |
Average user can use the dropdown box block, dynamically look up procedures by name is an advanced usage for experienced users. The PR bring more possibilities for App Inventor. |
@ewpatton Block |
Agree with @ewpatton that the dropdown is necessary. I would also recommend hiding the more advanced blocks (this might be something we need to address with the planned feature to hide blocks/components) because it could confuse new programmers to see so many blocks under the procedures drawer. |
Can one of the admins verify this patch? |
@ColinTree how to work with run in background blocks and run after period? Can you show some example , how to use that ? And can you explain about that? |
You can put an function start(procedure, time), which puts a run after period block, millis=time, passes in an anonymous function, and calls the start(procedure, time) function to form a recursion. |
This PR implements anonymous procedure defining and calling. As suggested by @wxbit, name
anonymous procedure
is avoid to be displayed in these blocks, in order to avoid increasing learning costs.What's more, blocks
get procedure
&calling procedure with input list
are suggested by @wxbit. (Thank you!)With anonymous procedure introduced into appinventor, callbacks can now be defined and implementing multi-thread blocks can be added into the plan.
Need help/suggestion:
Blocks added (in control)
(in category procedure):
Some samples:
calling a global defined procedure
Calculating with mode switcher
Calculating with mode switcher (2)