I’m quite new to Elixir and functional programming in general so bear with me if this is a ‘duh’ moment.
I am trying to view the @spec I made, but I keep getting an undefined function function error in IEX.
@spec calc_fall_vel(number()) :: number()
def calc_fall_vel distance do
:math.sqrt 2 * 9.8 * distance
end
and trying to call s() results in:
iex(39)> s(Drop.calc_fall_vel)
** (CompileError) iex:39: undefined function s/1
iex(39)> h s
No documentation for Kernel.s was found
iex(40)> s(Drop)
** (CompileError) iex:40: undefined function s/1
I’m not sure where s/0 is suppose to come from. However, if you use h Drop.calc_fall_vel, that should display the spec along with the documentation for that function.
Another thing was that ‘h’ didnt work either. Turns out, that I needed to compile with ‘c’ and give it a path to put the beam file, and the book did not mention that in any of the code examples, so the beam stayed in memory were the docs didn’t get created with it.
I did:
iex(8)> c("drop.ex", ".")
to get the beam to show up in the directory, then:
iex(9)> h Drop
Drop
Calculates the falling velocity of an object falling to earth, or any other
planet if the value for gravity is provided.
iex(10)>
Worked fine.
This is not promising for the book unless I was missing something.
I just looked on Safari Books. There is a second edition of that book and in that section it uses h/1. In the first edition, it uses s/1 like you said. That probably got changed to t/1 that @axelson mentioned.