Created
September 29, 2025 17:41
-
-
Save usergenic/dddfe7758de99fd190369452d483a9c5 to your computer and use it in GitHub Desktop.
example dsl to support prolog in ruby using instance eval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extend Prolog | |
| facts do | |
| # possibly symbols/strings are interchangeable for atoms | |
| # since symbols are convenient | |
| editor(:alice, :vim) | |
| editor(:bob, :emacs) | |
| editor(:carol, :vim) | |
| editor(:devon, :emacs) | |
| keyboard(:alice, :qwerty) | |
| keyboard(:bob, :qwerty) | |
| keyboard(:carol, :dvorak) | |
| keyboard(:devon, :qwerty) | |
| end | |
| # Rules method makes all method calls handled by a method_missing handler on a RulesDefinition instance | |
| rules do | |
| can_pair(:@person_1, :@person_2) do | |
| editor(:@person_1, :@x) & | |
| editor(:@person_2, :@x) & | |
| keyboard(:@person_1, :@y) & | |
| keyboard(:@person_2, :@y) | |
| end | |
| end | |
| query do | |
| can_pair(:@x, :@y) do | |
| # this block would be instance eval'd on a Prolog::Result | |
| puts "#@x can pair with #@y" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment