Unnecessary thing in the manual

when the reference manual talks about writing our own

(if <> then [] else [] :: control)

block, it shows you how to make an id block. we already have it:

([id v] of () :: operators)

just asking to change it!

the if then else reporter that the manual makes, is different from the primitive. The primitive one doesn't call the inputs, it just reports them. Here
unknown blocks script pic (2)

btw, to fix that error, just put a report block under the say block.

also, I can't find the id block anywhere in the snap editor (as a primitive)

it is a option in the
[ v] of () :: operators
operators block

True (only recently), but I think that what it does will be clearer if we show the code to implement it in Snap!. Jens added it as a primitive so that it would be a hyperblock, so that you can (shallow) copy a list by using it as the input to ID.

Oh, and the other side of that feature is that you can't use the primitive ID to report its input without copying, supposing that input is a list.

The manual shows three different attempts at reporter IF. The first, straightforward one works for simple cases but generates infinite loops in recursive functions. The second, the one that needs ID for simple inputs, declares the second and third inputs to be reporters, so there are rings in the block, which means you can't type into them for numbers or text, hence the need for ID. The third one combines the best features of the other two by declaring those inputs to be Any (Unevaluated). That third version works exactly like the primitive. I suspect you got confused about this because you were reading the second one in the manual, and so you thought you were supposed to put an explicit ring around that second input. Your picture corresponds to the second manual version, not the third.

but we already have

join [] []


report [] :: control cap

which can be used in this purpose

yeah, I didn't read the next page so I didn't see the third option. The one in my picture is the second one.

no, I mean it says we need id because you can't type in rings. we already have the id block, and if we didn't you can do

[scratchblocks] report (my if <(n)=(0)> then ({report [1] :: control cap} @addInput :: grey ring) else (((n) × (factorial ((n) - (1)) :: operators) :: operators) @addInput :: grey ring) :: control) :: control cap [/scratchblocks]

Oh, right, it's pretty recent that you can put a script with a REPORT block in a Reporter-type input slot. And, again, although we do have the primitive ID hidden in the SQRT block's menu, I think readers unfamiliar with the idea of the identity function will understand it better if they see the (very simple) definition. We don't pay by the pixel. :~)

But yeah, I'll think about using REPORT. Thanks.

oh, I thought that would be an old feature. anyways, ok.

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