cie / rubylog

A Prolog DSL and interpreter for Ruby
MIT License
31 stars 1 forks source link

uninitialized constant while trying to run examples #2

Open grych opened 11 years ago

grych commented 11 years ago

Hi, This is a great idea to implement Prolog in Ruby! However, when I am trying to run the examples, I am having uninitialized constant error, like:

rubylog1.rb:8:in `block in <main>': uninitialized constant N (NameError)
    from /Users/grych/.rvm/gems/ruby-1.9.3-p385/gems/rubylog-1.0.0/lib/rubylog/theory.rb:121:in `instance_exec'
    from /Users/grych/.rvm/gems/ruby-1.9.3-p385/gems/rubylog-1.0.0/lib/rubylog/theory.rb:121:in `with_context'
    from /Users/grych/.rvm/gems/ruby-1.9.3-p385/gems/rubylog-1.0.0/lib/rubylog/theory.rb:35:in `theory'
    from /Users/grych/.rvm/gems/ruby-1.9.3-p385/gems/rubylog-1.0.0/lib/rubylog/mixins/kernel.rb:3:in `theory'
    from rubylog1.rb:3:in `<main>'

I am running ruby 1.9.3p385

cie commented 11 years ago

Hi! Thanks a lot for the feedback!

Unfortunately, currently it only works in 1.9.2. I use this mechanism to use constants for variables:

class << self
  def self.const_missing name
    :hello
  end
end
Something # => :hello

This has worked in 1.9.2 and does not work in 1.9.3 and 2.0. I hope I can find a different solution with refinements for 2.0, but until mid July I cannot work much on it.

Is it possible for you to use it on 1.9.2? If not, I'll try to find a workaround.

By the way, I've just released 2.0pre1, so could you please use that version, as it has many new features and many differences in the DSL.

grych commented 11 years ago

This has worked in 1.9.2 and does not work in 1.9.3 and 2.0. I hope I can find a different solution with refinements for 2.0, but until mid July I cannot work much on it.

Is it possible for you to use it on 1.9.2? If not, I'll try to find a workaround.

No problem, I will use 1.9.2. By the way, I've just released 2.0pre1, so could you please use that version, as it has many new features and many differences in the DSL.

I will take a look. Thx again!

Grych

EHadoux commented 10 years ago

As I can see for now, I have this problem too on Ruby 2.0.0-p195 if I use the rubylog do syntax. However, with the extend Rubylog::Context one, it seems to work like a charm (on my own code at least, I did not run the examples).

cie commented 10 years ago

Hi! Great that you are interested in Rubylog. Unfortunately Ruby 1.9.3 and 2 include an improvement that makes implemememting the rubylog do syntax impossible. So in this sense it is deprecated.

EHadoux commented 10 years ago

I got it :) I think it will be worth the mention in the readme, no? Great job anyway.

EHadoux commented 9 years ago

Hello, it has been a while. Do you plan to support Ruby 2 on day or do you know a alternative to rubylog? Unfortunately, every stuff I've found are either too old or not as powerful :( For instance, I have predicates attack(a,b), attack(b,c) but I cannot express a rule like

dominated(X) :- attack(Y,X), a_way_to_say_there_is_no_Z_such_as_attack(Z,Y)
cie commented 9 years ago

Hello,

First of all, I'm so happy that someone is using my language! I'm not using it currently in any active project, so I'm not working on it for my own benefit. However, if I can help you with any answers, bug fixes or small features, I'd be happy to do so.

Rubylog does support Ruby 2, I just didn't update the Readme until now (now I did). But I'm not sure I understand your concern. Did this cause you a block? Then sorry for my lack of communication. As I understood from your comment, you managed to use Rubylog with the extend Rubylog::Context. The standard way to use it is this:

require "rubylog"
module MyRubylogCode
  extend Rubylog::Context

  # your rubylog code here
end

Another way is to use the rubylog executable with a file that contains Rubylog code:

$ rubylog myfile.rb

This is the way you can run the examples too.

Rubylog is quite under-documented because this was my BSc thesis work, and as I got closer to the deadline, I rather worked on the code and the thesis, not the documentation. And now, as I don't use Rubylog anymore, it's a bit orphaned :)

BTW, is your project Open Source? I would be happy to see your Rubylog code, and maybe I could give you some suggestions too.

EHadoux commented 9 years ago

You're right, I'm sorry. I had the uninitialized constant stuff while using the extend way, so I assumed it was a version problem but it may have been a human problem. Anyway, this is working! My code is open sourced but the Rubylog is not inside yet, i'll drop the link here when it will be. Thanks very much :)

cie commented 9 years ago

You're welcome :)