Cant use s() to view specs in IEX: "Undefined function"

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

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

Not sure what is going on here. Thanks.

Hi @cahlips,

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.

You can see the helpers available in IEx here:

1 Like

It was in the book I was using oddly enough.

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


Calculates the falling velocity of an object falling to earth, or any other
planet if the value for gravity is provided.


Worked fine.

This is not promising for the book unless I was missing something.


Which book and what version is it?

Introducing Elixir (1st edition) by Simon St. Laurent and J. David Eisenberg.

Page 23.

I think you’re looking for IEx.Helpers.t/1. Try typing

iex> t Drop.calc_fell_vel

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.