Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 1.1-TheElementsOfProgramming/ex-1.4/icarosun.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# It not run in elixir

# (define (a-plus-abs-b a b)
# ((if (> b 0) + -) a b))

a_plus_abs_b = fn
a, b when b > 0 -> a + b
a, b -> a - b
end

# IO.puts(a_plus_abs_b.(10, 1))
#
# The application will check if b is positive or negative. If b is negative, it will perform the
# subtraction operation; otherwise, it will perform the addition operation. Therefore, b will always
# be treated as an absolute value
38 changes: 38 additions & 0 deletions 1.1-TheElementsOfProgramming/ex-1.5/icarosun.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# it no run in elixir

# (define (p) (p))
# (define (test x y)
# (if (= x 0) 0 y))

defmodule Exercise do
def p() do
p()
end

def test(x, y) do
if x == 0 do
0
else
y
end
end
end

IO.puts(Exercise.test(0, Exercise.p()))

# The code will enter a loop
#
# In applicative-order evaluation the code will enter a loop.
# Applicative-order evaluation checks the argument first, then the the function
#
# (test 0 (p))
# (test 0 (p)p)p)...)
#
# In normal-order evaluation, the code will run and finish by printing a zero.
# Normal-order evaluation first check the function before the arguments the arguments
#
# (test 0 (p))
# (if (= x 0) 0 (p))
# (if (true) 0 (p))
# 0
#