Jump to content

Y combinator: Difference between revisions

m
→‎{{header|Julia}}: Restored the Julia version of Ismaei-vc
(Undo revision 345797 by Ismael-vc (talk) Reverted change that had deleted a lot of the page)
m (→‎{{header|Julia}}: Restored the Julia version of Ismaei-vc)
Line 3,442:
=={{header|Julia}}==
<lang julia>
""" _
julia> """
_ _ _(_)_ | Documentation: https://docs.julialang.org
# Y combinator
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.6.3 (2021-09-23)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
 
julia> using Markdown
* `λf. (λx. f (x x)) (λx. f (x x))`
 
"""
julia> @doc md"""
# Y combinatorCombinator
 
* `$λf. (λx. f (x x)) (λx. f (x x))`$
""" ->
Y = f -> (x -> x(x))(y -> f((t...) -> y(y)(t...)))
Y
</lang>
 
Line 3,453 ⟶ 3,465:
 
<lang julia>
julia> fac = f -> (n -> n < 2 ? 1 : n * f(n - 1))
julia> "# Factorial"
#9 (generic function with 1 method)
fac = f -> (n -> n < 2 ? 1 : n * f(n - 1))
 
julia> fib = f -> (n -> n == 0 ? 0 : (n == 1 ? 1 : f(n - 1) + f(n - 2)))
julia> "# Fibonacci"
#13 (generic function with 1 method)
fib = f -> (n -> n == 0 ? 0 : (n == 1 ? 1 : f(n - 1) + f(n - 2)))
 
julia> [Y(fac).(i) for i = 1:10])
10-element ArrayVector{Any,1Int64}:
1
2
Line 3,472 ⟶ 3,484:
3628800
 
julia> [Y(fib).(i) for i = 1:10])
10-element ArrayVector{Any,1Int64}:
1
1
3,049

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.