rubylog 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +38 -33
  2. data/VERSION +1 -1
  3. data/rubylog.gemspec +1 -1
  4. metadata +3 -3
data/README.rdoc CHANGED
@@ -7,32 +7,35 @@ Rubylog is an implementation of (part of) the Prolog language as a Ruby DSL. The
7
7
 
8
8
  == Using
9
9
 
10
- To get started you have to do three things: require rubylog, include +Rubylog::DSL::Constants+ and declare some functors on a class you want to use:
10
+ To get started you have to do three things: require rubylog, include Rubylog::DSL::Constants and declare some functors on a class you want to use:
11
11
  require 'rubylog'
12
12
  include Rubylog::DSL::Constants
13
13
  Symbol.rubylog_functor :likes, :drinks, :has
14
14
 
15
15
  A Rubylog clause can be created by sending the functor to the first argument, passing the other arguments:
16
- :John.likes :beer # likes(john,beer) in Prolog
16
+ :john.likes :beer # likes(john,beer) in Prolog
17
17
 
18
18
  A variable is an undefined constant. Don't-care variables start with ANY...
19
19
  A, B, Cat # the same in Prolog
20
20
  ANY, ANYONE, ANYTHING # _ in Prolog
21
21
 
22
22
  Now you can start writing Rubylog predicates. Facts can be asserted with a bang:
23
- :John.likes! :beer # likes(john, beer). in Prolog
24
- :John.has! :beer # has(john, beer). in Prolog
23
+ :john.likes! :beer # likes(john, beer). in Prolog
24
+ :john.has! :beer
25
+
26
+ Fact assertions return the first argument, so they can be chained:
27
+ :john.likes!(:beer).has!(:beer)
25
28
 
26
29
  Rules can be asserted with +if+ and +unless+:
27
30
  X.drinks(Y).if X.has(Y).and X.likes(Y) # drinks(X,Y) :- has(X,Y), likes(X,Y). in Prolog
28
31
 
29
32
  Queries can be proved with a question mark or with +true?+:
30
- John.drinks? :beer # => true
31
- (John.drinks :beer).true? # => true
33
+ :john.drinks? :beer # => true
34
+ (:john.drinks :beer).true? # => true
32
35
 
33
36
  Or solutions can be enumerated (clauses include Enumerable)
34
- (John.drinks X).each {|x| p x} # outputs :beer
35
- (John.drinks X).to_a # => [:beer]
37
+ (:john.drinks X).each {|x| p x} # outputs :beer
38
+ (:john.drinks X).to_a # => [:beer]
36
39
 
37
40
  At most places you can mix native Ruby with Rubylog by using a proc instead of a clause. Blocks are automatically converted to proc objects:
38
41
  X.drinks(Y).if proc{|x,y| y.to_s =~ /^Z/ }
@@ -44,7 +47,7 @@ At most places you can mix native Ruby with Rubylog by using a proc instead of a
44
47
  Variable values are passed to the proc, in the order of appearance.
45
48
 
46
49
  Nullary predicates are just symbols:
47
- John.drinks(:beer).if :true.or :false
50
+ :john.drinks(:beer).if :true.or :false
48
51
 
49
52
  For predicates requiring a simple value as an argument, you can pass a proc that returns that value
50
53
  X.drinks(Y).if Y.is proc{|x| $favorites[x] }
@@ -53,34 +56,36 @@ For predicates requiring a simple value as an argument, you can pass a proc that
53
56
 
54
57
  The Prolog built-in predicates and the Rubylog equivalents (see +Rubylog::Builtins+ for details):
55
58
 
56
- <table>
57
- <tr><th>Prolog</th><th>Rubylog</th></tr>
58
- <tr><td>+true+</td><td>+:true+</td></tr>
59
- <tr><td>+fail+</td><td>+:fail+</td></tr>
60
- <tr><td>+,+</td><td>+and+, +&+</td></tr>
61
- <tr><td>+;+</td><td>+or+, +|+</td></tr>
62
- <tr><td>+!+</td><td>+:cut+</td></tr>
63
- <tr><td>+->+</td><td>+then+</td></tr>
64
- <tr><td><tt>\\\+</tt></td><td>+is_false+, +fails+, +not+, +~+</td></tr>
65
- <tr><td>+repeat+</td><td>+repeat+</td></tr>
66
- <tr><td>+A=B+</td><td>+A.is B+</td></tr>
67
- <tr><td><tt>X is Y*5</tt></td><td><tt>X.is{|y|y*5}</tt></td></tr>
68
- <tr><td></td><td>+proc{|x,y|y===x}+ or +X.matches Y+</td></tr>
69
- <tr><td>+L=[H|T]+</td><td>+L.splits_to(H,T)+</td></tr>
70
- <tr><td>+member(A,L)+</td><td>+A.in L+ (+L+ can be any enumerable)</td></tr>
71
- <tr><td>+write(A)+</td><td>+A._puts+, +A._print+, +A._p+</td></tr>
72
- <tr><td>+nl+</td><td>+:nl+</td></tr>
73
- <tr><td><tt>\\\+((A, \\\+ B))</tt></td><td>+A.all B+</td></tr>
74
- <tr><td><tt>(A,B)->true</tt></td><td>+A.any B+</td></tr>
75
- <tr><td><tt></tt></td><td>+A.one B+</td></tr>
76
- <tr><td><tt>\\\+((A,B))</tt></td><td><tt>A.none B</tt></td></tr>
77
-
78
- </table>
59
+ Prolog Rubylog
60
+ ----------------------------------------
61
+ true true
62
+ fail fail
63
+ , and, &
64
+ ; or, |
65
+ ! :cut
66
+ -> then
67
+ \+ is_false, fails, not, ~
68
+ repeat repeat
69
+ A=B A.is B
70
+ X is Y*5 X.is{|y|y*5}
71
+ proc{|x,y|y===x} or X.matches Y
72
+ L=[H|T] L.splits_to(H,T)
73
+ member(A,L) A.in L (L can be any enumerable)
74
+ write(A) A._puts, A._print, A._p
75
+ nl nl
76
+ \+((A, \+ B)) A.all B
77
+ (A,B)->true A.any B
78
+ A.one B
79
+ \+((A,B)) A.none B
80
+ A,fail;true A.all
81
+ A->true A.any
82
+ A.one
83
+ \+(A) A.none
84
+
79
85
 
80
86
 
81
87
 
82
88
  == Contributing to rubylog
83
-
84
89
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
85
90
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
86
91
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/rubylog.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubylog}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bern\303\241t Kall\303\263"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubylog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
9
+ - 1
10
10
  segments_generated: true
11
- version: 0.0.0
11
+ version: 0.0.1
12
12
  platform: ruby
13
13
  authors:
14
14
  - "Bern\xC3\xA1t Kall\xC3\xB3"