An ongoing project: Purely Functional Snap!

I've started working on a set of blocks that allows you to create purely functional Snap! programs!

Here it is!

Currently, the only blocks I've made are:

  1. an inline loop (it repeatedly calls a block with data, then sets data to the output.)image
  2. Operators with a dropdown to select the operation (I'm aware that this doesn't relate to Functional programming, I just wanted it)image

I'm excited to implement functional movement, where you pass in a pair of coordinates, and it generates a set of movements that can be run internally. My plan is to abstract away the movement, so that the user thinks that the block is returning a new object at different coordinates.

Aargh I should have seen this a week ago, but somehow I've gotten about 50 threads behind the forum and I missed it. I'm looking forward to seeing where you take this.

Your THEN block has a specific first step built into it. I get that you're still developing that block and didn't announce it as ready.

What is the purpose of your RUN block for reporters? I mean, why not just use CALL?

I have two suggestions about the naming of the loop block. First, the ➞ suggests that that second input slot is just the return value of the function, but it's also the input value. And also, the × symbol suggests to me that you're actually multiplying something by the following (third) input. That's why I used # for a similar purpose in the list processing library. It's the number of times to do something.

But in fact there's a standard math notation for f(f(...(f(x)))): fn(x). So you could say untitled script pic (2) supposing you don't want to do fancy formatting of the block with spaces and $nl .

But that's just a suggestion; it's your language and you should use a notation that feels comfortable to you.

I used run for a block, but I deleted the block I needed it for b/c it wasn't purely functional.

Huh. I didn't know that.

it's interesting to see how you implemented loops using only reporter/boolean blocks.

We already have the cascade block in the Iteration, composition library.

I know. I wanted to try to make one myself.

There are many replications of it without realizing there is a library for it. Mine looks like this:

I'm trying to make motion blocks, but I'm having trouble with
image

i can't seem to get the custom block from that script pic

Is the motion block actually supposed to make the full object move? Or is it supposed to report a moved version of it?

Is this what you mean?

No. It reports an object.
Purely Functional Snap! script pic
image
Purely Functional Snap! script pic1

Thanks! Even though it doesn't report the new object, it helped me see that I reversed the trig functions. (I thought it was like the unit circle. I was wrong.)

Heh.
Purely Functional Snap! script pic

Motion is done! I'm gonna work on looks!

Can I try and make the list blocks? I think they will actually have a lot of use cases in projects

Doesn't Snap! already have functional list blocks?

There's also 3 imperative list blocks you already removed: add, replace, delete. Replacing these by functional blocks, and without imperative commands under the hood, isn't trivial because of the dictionary features introduced with Snap! 8.

BTW: nice project!

Could I use map? Or keep?