Help using the "Set block definition" to make custom-block report a List

What's problem you are encountering?
I want to programmatically create/edit custom-blocks, in this case, of the "reporter" type supposed to report a script-created List; pretty simple, in theory.

The respective List I want my reporter block to report:

  • The List consists of unique Blocks of many different Sprites with varying scopes.
  • It has to be modular (not hard-coded) because those blocks may be created/modified/deleted at any time and the list must reflect that.

What have you tried that didn't work?
Way too many things; some examples:

  1. The most promising trial, so far (failed):
  • Reports:
    Masteric Framework v1 script pic (2)
  • Because the script seems to try and conjoint the List as an unified input instead of reporting the entire list, as its expected; here's how the custom-block's definition turns out:
    Masteric Framework v1 script pic (3)
  1. The block rejects, from the most intuitive methods...

    image
  2. To the most extravagant and creative fever dreams:

  3. Some more direct approaches sends the variable's out-of-scope addresses instead of their values:

    Masteric Framework v1 script pic (9)
  • I've tried many, many more different things other than those example pictures above, to no avail.

It's not the first time I run into such problems into my projects, nor the first time I call for help into these forums and leave unattended, unfortunately.
"SNAP!" is not well-documented regarding these "meta-programming" blocks and their correct usage (or maybe into my specific situations) and I've really run out of ideas and other stuff to do while I post-pone this issue.

So, please, if anyone can help me out with this, I'd be able to continue my project; otherwise, I don't see any better ways to do what I've been planning to do as far as custom-blocks go, which shouldn't be all that hard as far as I conceive it - yet, not before I solve this SNAP shenanigan. Any help would be appreciated. Thanks, folks.

Let me get this straight, you want to get all the blocks in every sprite?

Amongst other things, yes. The main issue always being centered around the Masteric Framework v1 script pic (10) block never working as I'd imagine.
To further elaborate:


There are many scripts with differing functionalities that would make use of procedural custom-block creation, always turning out to be set-backs because I can never manage to correctly set up custom-block definitions with those; they almost aways never work as intended.

So, how can I:

  • Pass evaluated values from variables to procedurally-created custom-block's definitions to never rise "x variable doesn't exist in this context" errors?
  • Make custom reporters report something such as a List that results from any script?

To get every block in every sprite, I would suggest this script

But apparently the ([uniques] of []) block runs very very slowly when it comes to blocks in a list.


About your problem, adding evaluated values from variable to custom block definitions, I can show you how. The best thing to do is to create the definition outside the block (with metaprogramming), and see what you're creating before actually setting it. I don't have time to explain all of the quirks of metaprogramming, but you can create a script, then 1000342113, and explore that result. Essentially, you want to try and recreate that same kind of structure.

I've tried out your suggestion regarding metaprogramming during this specific situation at this post, specifically the "split by block" part (and joining the new values either by re-map or other loops and logic), however, it ceases to work anyway when everything should fall together into the
Masteric Framework v1 script pic (10) block, the major issue always being the block unevaluating the calculations and/or the variables.


About your script suggestion to get all agent's blocks, I can say it is almost identical to my first take on it, but I switched on to more "obscure" methods because of the impact into performance that evaluating Lists of blocks has on the project. I've done it this funky way to avoid throttle and be stylish:

  • Result:
    SNAP_progress_IDE_example
  • My intention was to make it work as a "background process" and allow other stuff to be done within the thread, I've experimented a lot to get some statistics about the performance, and I suppose this worked well, so far. I am/will be doing many concurrent stuff in this project, such as calling both ChatGPT and Stable Diffusion APIs at some point, which can be costly at times. More than once I lost some progress into my projects to pesky "Out of Memory" crashes...
    Masteric Framework v1 script pic (13)
  • This is how I hijacked "SNAP!" IDE's UI to my bidding, lol

I don't understand why this is a metaprogramming problem at all. As you noted, MY BLOCKS gets you almost the information you want, and then you just do plain list processing on it. What am I missing? Sorry for being thick.

Of course not, my friend. I am the one apologizing because I know how bad I can be at explaining things, I get carried away too often. Besides, I lack proper education and find myself struggling to come up with the technical terms that could help clarifying what I am trying to do.


Very Long Explanation:

I am making a project on SNAP! that I intend to use as a base, or rather, a framework to reutilize and connect between other projects. I am doing it similarly as to what SciSnap! did, perhaps, but this will be a library focused on nothing in particular, except, leveraging SNAP! native functionalities, making creating anything specific in the future much easier.
To achieve that, I am actively experimenting with different architectures and strategies, as they come to mind, leveraging SNAP!'s unparalleled efficiency to prototype such things.

At some point, I noticed it was helpful to create pairs of Sprites as Prototypes and assign each category of Blocks to their respective Sprite-Scopes (akin to how organizing complex states on Stages can be handy).

A few of the libraries I am making include:

  • Objects (A library to manage and control Clones into way more advanced/organized ways)
  • IDE (A library to give more control over the editor, like making backups/autosaves, add some missing functionalities - such as selecting a specific Agent during file's drag 'n drop events, creating custom IDE prompts/table prompts/file import prompts, changing blocks on-the-run such as updating their repertoires of menus and available choices/custom errors based on user's interactions with it, etc;)
  • Data (A library to create and manage custom formats based on Tables of key-value pairs, add new types of data - such as .MIDI, HTML and .MarkDown - remove ambiguity from the native variable types, if necessary; easily create custom parsers to resolve code, etc;
  • Renderer (Advanced form of Pen with many predefined structures focused on GUI creation, such as UIs, or render/draw parsed Data such as MD and HTML, etc.
  • System (A library that holds and manages project-specific and user-specific data and is a "subsidiary" of IDE, saving defaults, browser-data - such as holding API keys, globally-shared/locally-shared galleries of Custom-Blocks, etc.)

There's more stuff, much is scattered amongst two years of daily "SNAP!"ing in exile inside my secluded cave as I figure out all this stuff by myself, but now that I know how to build an entire OS with Blocks its nearly time I move on to Python or some other stuff, so I want to make some contribution before I go.


TL;DR:

  • Figuring out how to correctly define any block with the
    Masteric Framework v1 script pic (10) block is finding the Fifth Infinity Ston- Is a recurrent requirement into my project; I need to be able to define reporter blocks as if they were variables, on occasion; also I may interact my projects with external APIs that would send JSON or other formats in order to generate Custom-Blocks on-demand.
  • This post I wrote here and my current issue serves as one example of the many situations I tend to face with this block.
  • Are there any tutorials somewhere that describe how to use it effectively that someone can point me to, or show me the solution for the original issue at this post so I can reverse-engineer it until I crack-the-code rather than my head?

Thank you and community.

:rofl:

:rofl: :rofl:
:rofl: :rofl:
Anyways,

Yes, that's what it is.
I liked the explanation, but honestly, that's outside my Snap!, and for that matter programming, expertise. Maybe someone like @bh could help with that?

I'm not sure I understand what exactly it is you're trying to do (and if it's a good idea). If you're looking into metaprogramming you might be interested in some things that are currently in development for v10 - and still very experimental / buggy / incomplete:

Blockify: Make a block that takes a data structure and makes a block that makes the data structure. This one you already do in the current version.

Scriptify: Make a block that takes a block and makes a block that makes the block. (coming up this summer in v10).

And then 2 methods to turn blocks into text and back again, both coming up this summer in v10:

Encode: Make a block that takes a block and makes a text that can be split to make a script that makes the block.

(you'll also be able to directly copy text to the clipboard then)

Parse: Make a block that takes a text and makes a data structure that can be assembled into a script of blocks.

All of this is currently in development and still very much in flow, so please things to change until the release.

:~D This cracked me up!

But seriously, your work sounds fascinating to me. Systems programming is the kind of thing I like to do, too. Do you have anything sharable yet? Not to use, necessarily, just to look at?

One of the many, many things I'm supposed to be doing that I've dropped the ball on is to build a Scheme-style hygienic macro system on top of Jens's metaprogramming primitives. I think that would improve life for people interested in metaprogramming. Maybe you'll inspire me to get off my butt about that!

I liked the explanation, but honestly, that's outside my Snap!, and for that matter programming, expertise.

Oh, Snap!... that's unfortunate. But I am glad you liked my villain's origin backstory. I'll figure out that stuff, eventually, and complete my Infinit- project, then share whatever's not too shameful to display, lol. Thanks anyway, my dude.

I'm not sure I understand what exactly it is you're trying to do (and if it's a good idea).

Didn't expect less, professor. Even oblivious of my real motives you were the only one capable of sensing the dangerous power that emanates from within my framework. - sorry, just kidding.

Thank you for your reply and your time, professor. I am really impressed with the elegant solutions I find at those scripts you shared with us; I already saved them to study, if you don't mind. I must admit recursion is one entire concept I have a real hard time grasping on, except when I see it applied like that. Very sophisticated.

I can also already spot a lot of additions to SNAP!'s IDE itself - how I wish I could simply "copy" text bubbles from time to time... I am excited for the new release and those metaprogramming additions.

Regarding the Blocks to Text and vice-versa, I did something similar a few months ago, but yours beats mine in terms of sophistication (size and probably performance) a hundred times; mine was a mess and barely working.

I'll see if any of those scripts give me any insights regarding my current issues. Thank you and all the other devs, again, for enabling us so many ways and tools to learn about the most important skill of this age.

not a prof, haha! (I'm just a lawyer turned astray to impersonate a programmer).

Hmmmm, I might have something in a few hours, then. I'll clear it up and show you some ideas I had that might inspire you, good dev, but as I said, I lack the traditional knowledge of the thing and these terminologies. I am also looking up this Scheme-style hygienic macro thing and referential transparency to see if it rings a bell. I mostly reinvented the wheel with everything I touched - I like the sensation of learning how the wheels were made, however.

:rofl:

:rofl:
:rofl:

Yeah. The jokes put here-and-there were and are funny.

:rofl:yeah

Do you want something like this


Script local variables are replaced by their values.
Global vars and parameters are left intact.
untitled script pic - 2024-03-02T014734.392
Serialization (i.e. blockify/scriptify) of the complex list has some flaws, so a double ring is required (now).


You may also use a shared storage pattern - reporter that stores/reports values.
untitled script pic - 2024-03-02T023811.141

untitled script pic - 2024-03-02T022945.688

I think what he wants is hybrid scope, the same thing I've wanted all along, so when you're about to get an error message because there's no binding in the lexical environment, we check the dynamic environment instead. But Jens convinced me that there would be too much of a performance cost even for projects that don't take advantage of it.

I think it's possible that without redefining blocks you could use untitled script pic (2) inside a
untitled script pic (3)
to get the same effect. On my never-ending list of things to try when I work up the energy.

I think it's more of a bulky, mutable state. Quite similar to the one used by yours "Colors and Crayons" library. A global variable serves this purpose well enough but does not play well with the libraries.
A block variable disguised as a setter/getter looks smarter :wink:
Setter
untitled script pic - 2024-03-02T230332.969

Getter
untitled script pic - 2024-03-02T230335.865

The initial concept, involving metaprogramming, seems like a random way to implement lazy initialization and caching (memoizing) of the state.


The "Create variables" library already implements a dynamic scoping.
That "macro"
memoize script pic (11)
mutates the last (or first going backward) memoize script pic (14) available along the scope stack

memoize script pic (12)

Hmm, maybe we should let @tonyorcy speak for himself about what he actually wants...

Huh. You're right! That's not what its help text says. I wonder how that works?