crystal-community / icr

Interactive console for Crystal programming language
MIT License
505 stars 40 forks source link

Enable function listing with tab #86

Open lowks opened 6 years ago

lowks commented 6 years ago

It would be great if icr can list down all the functionality of a type say an integer in icr. The example below is taken from IPython

screen shot 2018-01-10 at 11 09 53 am
veelenga commented 6 years ago

@lowks well, probably. Personally, I'm against this unless icr becomes a fully functional REPL see #79. Currently icr mostly used to quickly try few language features the user not confident with, so it takes only few minutes to interact with this app and probably most users will not need function listing. But, I may be wrong.

Crystal is compiled, which again brings some limitations and complexity in the implementation of this. But I found it still possible to do:

class Object
  def methods
    {{ @type.methods.map &.name.stringify }}
  end
end

10.methods.grep /^to_i/ # => ["to_i", "to_i8", "to_i16", "to_i32", "to_i64", "to_i128"]

If you are willing to try to implement it, please send a pull request, even on early stages. I will be happy to review.

KINGSABRI commented 6 years ago

I think these #79 #97 are supporting the idea