Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Fixed-point combinator
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Example implementations=== An example implementation of ''Y'' in the language [[R (programming language)|R]] is presented below:<syntaxhighlight lang="r"> Y <- \(f) { g <- \(x) f(x(x)) g(g) } </syntaxhighlight>This can then be used to implement factorial as follows:<syntaxhighlight lang="r"> fact <- \(f) \(n) if (n == 0) 1 else n * f(n - 1) Y(fact)(5) # yields 5! = 120 </syntaxhighlight>Y is only needed when function names are absent. Substituting all the definitions into one line so that function names are not required gives:<syntaxhighlight lang="r"> (\(f) (\(x) f(x(x)))(\(x) f(x(x)))) (\(f) \(n) if (n == 0) 1 else n * f(n - 1)) (5) </syntaxhighlight>This works because R uses [[lazy evaluation]]. Languages that use [[strict evaluation]], such as [[Python (programming language)|Python]], [[C++]], and other [[strict programming language]]s, can often express Y; however, any implementation is useless in practice since it [[infinite loop|loops indefinitely]] until terminating via a [[stack overflow]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)