Giter Site home page Giter Site logo

Comments (13)

Mic92 avatar Mic92 commented on June 12, 2024 3

I once built a proof of concept for C++ to make this possible: https://github.com/inspector-repl/inspector

from crystal-libraries-needed.

Sija avatar Sija commented on June 12, 2024 1

@jwoertink You could try using fancyline instead of libreadline.

from crystal-libraries-needed.

veelenga avatar veelenga commented on June 12, 2024 1

AFAIK readline (or fancyline) allows you to only interrupt execution and read/evaluate an interactive command (aka repl). binding.pry in ruby is much more than just readline. Let's look at the example:

require 'pry'

class A
end

def ruby_method1
end

def ruby_method2(a, b)
  binding.pry # <--- execution stopped here
end

ruby_method2 3, "a"
[1] pry(main)> a
=> 3
[2] pry(main)> b
=> "a"
[3] pry(main)> A.new
=> #<A:0x007f93e06910d8>
[4] pry(main)> ruby_method1
=> nil
[5] pry(main)> c
NameError: undefined local variable or method `c' for main:Object
from (pry):7:in `ruby_method2'

here pry knows the execution context it is running in, so it can show you the values of method args, create an instance of available class A and call a method. Also, it knows that there is no var c, for example. This is achieved by the Binding class in ruby:

Objects of class Binding encapsulate the execution context at some particular place in the code and retain this context for future use. The variables, methods, value of self, and possibly an iterator block that can be accessed in this context are all retained. Binding objects can be created using Kernel#binding, and are made available to the callback of Kernel#set_trace_func.

If we could have something similar in Crystal, it would be really easy to implement analog of binding.pry. Take a look at the first pry's release in ruby: https://github.com/pry/pry/blob/4fcf81b97601945945f43311532c164a93b44d7c/lib/pry.rb

But creating Binding may look like a challenge for Crystal...

from crystal-libraries-needed.

Sija avatar Sija commented on June 12, 2024 1

I made a pure crystal library that doesn't rely on readline called Term::Reader if anyone would like to use that for something like this. Not sure about the rest of the pry functionality though.

@watzon that's completely off-topic

from crystal-libraries-needed.

elorest avatar elorest commented on June 12, 2024

ICR exists. There's obviously some differences since crystal is a compiled language. I don't think it lets you use vim inside of it like pry.

from crystal-libraries-needed.

TheLonelyGhost avatar TheLonelyGhost commented on June 12, 2024

Honestly, I'd be happy with it if I could view source code or documentation for a class/module/method. Being able to "cd" into a construct (whether class or instantiated object) is incredibly helpful when debugging.

from crystal-libraries-needed.

jwoertink avatar jwoertink commented on June 12, 2024

I actually started working on a way to do this in ICR. The libreadline library actually has a lot of really useful features that would help us to achieve this. Also, somehow integrating lldb would as well. The issue with the readline is that it's lacking in crystal. I made an issue for one part crystal-lang/crystal#4067 which is macOS related, but that prevents me from moving forward.

I'd like to tackle this again if anyone wants to jump on board with me!

from crystal-libraries-needed.

elorest avatar elorest commented on June 12, 2024

from crystal-libraries-needed.

jwoertink avatar jwoertink commented on June 12, 2024

Yeah, that's what they say; however, similar code runs in other languages. I don't think it's a readline issue, but I don't know the library well enough to be 100% sure.

from crystal-libraries-needed.

schovi avatar schovi commented on June 12, 2024

@elorest For example Haskell is compiled too and there is really pretty interactive env for that. What is different from Crystal?

from crystal-libraries-needed.

citizen428 avatar citizen428 commented on June 12, 2024

@schovi GHC for Haskell has two modes, compiled and interpreted. runghc and ghci use the latter.

from crystal-libraries-needed.

schovi avatar schovi commented on June 12, 2024

@citizen428 thanks for explanation!

from crystal-libraries-needed.

watzon avatar watzon commented on June 12, 2024

I made a pure crystal library that doesn't rely on readline called Term::Reader if anyone would like to use that for something like this. Not sure about the rest of the pry functionality though.

from crystal-libraries-needed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.