# First Bloop program # If you put this in a file called "bloop1.rb" then you can run it # with an argument from the keyboard, e.g., typing # ruby bloop1.rb 2 will compute hyperexp(2) # successor is the only initial function def s(n) return(n + 1) end # plus is defined by repeatedly applying s def plus(a,b) a.times do b = s(b) end return(b) end # mult is defined by repeatedly applying plus def mult(a,b) ans = 0 a.times do ans = plus(b,ans) end return(ans) end # exp is defined by repeatedly applying times def exp(a,b) ans = 1 b.times do ans = mult(a,ans) end return(ans) end # hyperexp is defined by repeatedly applying exp(2,x) def hyperexp(a) ans = 1 a.times do ans = exp(2,ans) end return(ans) end a = ARGV[0].to_i print "hyperexp( #{a} ) = #{hyperexp(a)} \n "