Block workarounds (later became :lambda: calculus)

yes

I'll rename it :slight_smile:

Oh.

I can't look it up either.(no minus function in cheatsheet listed above)
Maybe I can do it like this:
Count the number of F()s (times it will repeat if you push a function to it) and add 1 to number 0 every time except the first (the decrement function)

That's a good idea. Now write the code! :~)

Isn't it just amazing that you don't need arithmetic as primitive in a programming language?

:smiley: I just did it when you posted this.
But Darn Timer

yep
But we need first class functions or rings :~)

Yes. Lambda and call.

And also normal order evaluation (what you get from Unevaluated input types), in order for recursion to work.

Ah, no, no, that's cheating. You don't have SET, just lambda and CALL. That's why it's hard!

ohh


Oh hey,dont I have the list blocks?
I mean cons and car
Made it now :slight_smile:
(b in front of times)

Ah

That's why you had to make CONS, CAR, and CDR!

:slight_smile:
ohhhhh yes
plus i found a way to store a lot of vars in a loop (church nums)
Darn timer forced me to wait a minute

I'm going to sleep, so don't expect an immediate comment on your next pass.

ok
I'll make division function

Brian, I would LOVE to have lesson material from you for Church numerals! I think this would be an AWESOME addition to the materials that we give to teachers and kids. Can we turn it into a CodeWeek activity maybe? THAT's the kind of stuff I'd like to see more!

Here's the BYOB version from a million years ago. I started rewriting it for Snap! a few thousand years ago, but got hung up on the unhelpful behavior of script variables when the same name is declared twice. Then I thought we had reached a compromise, but when we discussed it fairly recently you no longer remembered (?) the compromise that I do remember (?).
church.zip (149.3 KB)
PS @18001767679 no peeking until subtraction is done, purely functionally.

Do you mean division?(minus function has already been done :slight_smile: )

Oh, awesome! Last I saw this you had a stateful decrement function. Great job making it functional. When you're done with arithmetic, you'll have to start in on a serious lambda calculus text. Then you and @theaspiringhacker can start teaching each other.

Because you got to sleep and forgot to reload the page!

Why @theaspiringhacker?

uhhh but im just a student interested in programmming
PS:I have trouble impllementing control structures :frowning:
Look at the bad repeat while block.it just freezes the page if no range and throwing errors if range specifyed

So's he! But he has a special interest in functional programming. He likes to program in Haskell.

Yeah, I couldn't figure out what it was trying to do, with so many inputs! Were you trying to do this:

yep but the if then else has to be replaced w/ the ?: block

YAY!

OK fine so why did you find it hard? Do you not really trust recursive functions?

No but I got an error:

so I made it w/ a range

OHHHH! I get it.

The problem is in your ?: function. It breaks everything that depends on it; your subtraction didn't work for me, even though its code is correct. I blush that I didn't actually try it before. :~(

You correctly declare the second and third inputs to be of type Any (Unevaluated) because otherwise a recursion will just keep going when it hits its base case. But, having done that, in order to report the value of the chosen branch, you have to CALL whichever branch you choose:


It's that outer (pale color) CALL that you forgot. Do that and everything works.

PS In a true functional language, all evaluation of inputs would be delayed until needed with no extra effort.