Hm... that's pretty cool... how would we know what to work on? I dislike putting non-python placeholders in the code itself (if that's what you meant), as, as usual, we'd like the thing to work outside of the web notebook... even be able to edit it after the fact (and lose the blockly editability). I was already planning to do something hash-based to make sure you don't inadvertently destroy stuff.<br>
<br>    # blockly foo<br>    def foo(bar):<br>        baz = None<br>        return baz<br>    # endblockly foo<br><br>A quick thing to remember here is that part of the goodness of blockly is the type checking; crucial for visual feedback so that you don't try to add a string to an integer, even though python would happily oblige you! So this would yield:<br>
<br>    # blockly foo(int bar): str baz<br>    def foo(bar):<br>        baz = None<br>        return baz<br>    # endblockly foo<br><br>Doing comment-based stuff would be rough, as we'd have to write some tab-completion that knew how to work on fancy comments. Using a de facto standard like javadoc/rst would be an option, I suppose.<br>
<br>Keeping that in mind, I am thinking to a) keep tab completion and b) keep the blockly goodness, we'll need to help blockly out. Maybe something like:<br><br>    @blockly("foo", args={"bar": int}, _return={"baz": str})<br>
    def foo(bar):<br>        return baz<br><br>Disadvantage here is that the @blockly, which does nothing outside of the notebook, would be embedded in the code, which is lame.<br><br>Additionally, the output cell element gets obliterated every time, so the decorator approach might be weird... although, as long as you are ONLY editing a function (and the code doesn't do anything else), it could work. Actually, I don't know if the display would work correctly.<br>
<br>Also, doing OO with Blockly is not really supported right now: it doesn't really support the name-based accessing of an object's members, so the leap could be hard here (assuming the decorator) for an instance method:<br>
<br>    @blockly("__init__", args={"bar": int}, _self={"bar": int})<br>    class Foo(object):<br>        def __init__(self, bar):<br>            self.bar = bar<br><br>Which would create a variable Block named, literally, "self.bar" that you could set stuff to and access. However, at present, it would be hard to have more than one blockly editor per CodeCell.<br>
<br>Rambling now: need to write code. My next plan was to just try to get some variables into scope, as the definition of functions, etc. might be "Day 2" of "Learning Python Visually," but I'll keep some of these things in mind!