Questions about library blocks

So, I have a bunch of questions about how in the world some of the library custom blocks do and how they work. Would anyone be willing to answer some questions I have about them? I'll start with this one: What do all of the blocks in the "web services access (https)" library do? How do they work, and how do I use them? What are they even used for?

  1. The [] url: [] send: [] headers: [] block is the same as the URL block, just upgraded. The first input tells to get, post, put, or delete on a request. You're likely going to use GET. The second input is the URL to request. You can find many API's online in the intermet. The rest of the inputs allow you to know what to send and what are the headers.
  2. The current location block reports your location in latitude and longitude, which can be useful for map projects.
  3. listify converts JSON into lists. Try {"a": 1, "b": 2}.
  4. value at key [] of [] gets the value of a key in a list. Try {"a": 1, "b": 2} and get the value of "a" and get 1.
  5. key [] value [] could be useful to make a JSON for sending headers.

In short, the web services library is used for making http(s) requests to apis. You're most likely never gonna use it, unless you need to use some api, as well as sending data in the request outside the url (if it's just a simple GET request with no headers/data, you can just use the (url []) block).

So basically it does a whole lot of stuff that I don't understand at all XD Okay.

Okay.

What about the "Iteration, composition" library? I hardly understand some of the regular control blocks, let alone these extra complicated ones.

This is quite complicated for me, but I'll answer as best as I can.

  1. catch [] [] enables the throw block to execute, and when executed with the same tag as the catch block, will jump/skip to after the catch block.

  2. throw [] allows early exit from a script. It will cause to jump/skip to after the catch block if it's the same as the catch block.

  3. The reporter version of catch enables the two-input throw block to execute, and when executed, returns the value instantly.

  4. The two-input throw block when executed, will return the value from the reporter version of catch.

  5. if [] do [] and pause all is the same as the if block, except that when the condition is true and the statements are done, will pause the project, could be useful for debugging.

  6. ignore [] does nothing, could be useful for reporters and you don't care about the return value.

  7. cascade [] times [] [] [] returns the value called multiple times. The first input allows you to choose how many times you'd like to iterate. The second input allows you to choose an operation, like (3) + (). The third input allows you to choose an initial value. The fourth input is an upvar that indicates the nth cascade. For example, cascade [3] times [(3) + ()] [5] [#] returns 14.

  8. cascade until is returns the value called multiple times. The first input chooses the condition when it will stop iterating. The second input allows you to choose an operation. The third input allows you to choose an initial value. The fourth input is an upvar that indicates the nth cascade.

  9. compose returns the function x |-> f(g(x)), where f and g are the two inputs.

  10. repeat [] until [] is the same as repeat until, except that it runs the command at least once.

  11. repeat [] while [] is the same as repeat until, except that it runs the command at least once and checks until the condition is false.

  12. repeat while is the same as repeat until, except that it checks until the condition is false.

  13. The repeat block with an upvar is the same as the repeat block. The upvar returns the nth loop.

  14. The for block with step is the same as the generic for block, except that it allows you to choose how much it will increase/decrease. A step of 3 inrceases 3-by-3.

  15. let () be [] in loop allows you to define a variable inside a loop. You can drag the upvar to inside the loop to simulate data inside them.

Fun fact, these are the only custom blocks that have a hardcoded (image) help dialog in snap (the help dialog was made before adding a comment to a block definition created a help dialog).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.