As title says, I don't understand why f^:proposition^:_ y
is a while loop. I have actually used it a couple times, but I don't understand how it works. I get that ^:
repeats functions, but I'm confused by its double use in that statement.
I also can't understand why f^:proposition^:a: y
works. This is the same as the previous one but returns the values from all the iterations, instead of only the last one as did the one above.
a:
is an empty box and I get that has a special meaning used with ^:
but even after having looked into the dictionary I couldn't understand it.
Thanks.
f^:proposition^:_
is not a while loop. It's (almost) a while loop whenproposition
returns1
or0
. It's some strange kind of while loop whenproposition
returns other results.Let's take a simple monadic case.
This is what's happening: every time that
v y
is1
,(f^:1) y
is executed. The result of(f^:1) y
is the newy
and so on.y
stays the same for two times in a row → outputy
and stop.v y
is0
→ outputy
and stop.So
f^:v^:_
here, works likedouble while less than 20 (or until the result doesn't change)
Let's see what happens when
v
returns2
/0
instead of1
/0
.You can have many kinds of "strange" loops by playing with
v
. (It can even return negative integers, to use the inverse off
).