Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ichiban/prolog
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.2
Choose a base ref
...
head repository: ichiban/prolog
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.6.0
Choose a head ref
  • 16 commits
  • 19 files changed
  • 1 contributor

Commits on Dec 26, 2021

  1. Copy the full SHA
    dd36422 View commit details
  2. Merge pull request #129 from ichiban/fix-compare

    delegate comparison to each Term
    ichiban authored Dec 26, 2021
    Copy the full SHA
    fc785d9 View commit details
  3. Copy the full SHA
    3f21ecb View commit details
  4. add StreamProperty tests

    ichiban committed Dec 26, 2021
    Copy the full SHA
    2f88195 View commit details
  5. add more StreamProperty tests

    ichiban committed Dec 26, 2021
    Copy the full SHA
    99df942 View commit details

Commits on Dec 27, 2021

  1. add some more tests

    ichiban committed Dec 27, 2021
    Copy the full SHA
    1108da0 View commit details
  2. add SetPrologFlag tests

    ichiban committed Dec 27, 2021
    Copy the full SHA
    c47ebac View commit details
  3. Merge pull request #130 from ichiban/reduce-builtin-cyclo

    reduce cyclomatic complexity of builtins
    ichiban authored Dec 27, 2021
    Copy the full SHA
    1a5f9b7 View commit details
  4. ignore shebang line

    ichiban committed Dec 27, 2021
    Copy the full SHA
    ff6c844 View commit details

Commits on Dec 28, 2021

  1. add QuerySolution()

    ichiban committed Dec 28, 2021
    Copy the full SHA
    1eb3197 View commit details
  2. fix shebang line detection

    ichiban committed Dec 28, 2021
    Copy the full SHA
    a61a8d0 View commit details
  3. add QuerySolution tests

    ichiban committed Dec 28, 2021
    Copy the full SHA
    e2415fc View commit details
  4. Merge pull request #131 from ichiban/ignore-shebang

    ignore shebang line
    ichiban authored Dec 28, 2021
    Copy the full SHA
    f5d3c85 View commit details
  5. Merge pull request #132 from ichiban/query-solution

    add QuerySolution()
    ichiban authored Dec 28, 2021
    Copy the full SHA
    0be3195 View commit details
  6. add RegisterN tests

    ichiban committed Dec 28, 2021
    Copy the full SHA
    2534148 View commit details
  7. Merge pull request #133 from ichiban/add-register-n-tests

    add RegisterN tests
    ichiban authored Dec 28, 2021
    Copy the full SHA
    90f6baf View commit details
Showing with 1,354 additions and 698 deletions.
  1. +12 −0 engine/atom.go
  2. +13 −0 engine/atom_test.go
  3. +342 −431 engine/builtin.go
  4. +487 −192 engine/builtin_test.go
  5. +26 −2 engine/compound.go
  6. +14 −0 engine/compound_test.go
  7. +17 −0 engine/float.go
  8. +14 −0 engine/float_test.go
  9. +18 −0 engine/integer.go
  10. +14 −0 engine/integer_test.go
  11. +94 −0 engine/stream.go
  12. +11 −0 engine/stream_test.go
  13. +1 −73 engine/term.go
  14. +15 −0 engine/variable.go
  15. +23 −0 engine/variable_test.go
  16. +120 −0 engine/vm_test.go
  17. +35 −0 interpreter.go
  18. +71 −0 interpreter_test.go
  19. +27 −0 solutions.go
12 changes: 12 additions & 0 deletions engine/atom.go
Original file line number Diff line number Diff line change
@@ -63,6 +63,18 @@ func (a Atom) Unparse(emit func(Token), opts WriteTermOptions, _ *Env) {
}
}

// Compare compares the atom to another term.
func (a Atom) Compare(t Term, env *Env) int64 {
switch t := env.Resolve(t).(type) {
case Variable, Float, Integer:
return 1
case Atom:
return int64(strings.Compare(string(a), string(t)))
default:
return -1
}
}

func quote(s string) string {
return fmt.Sprintf("'%s'", quotedAtomEscapePattern.ReplaceAllStringFunc(s, quotedIdentEscape))
}
13 changes: 13 additions & 0 deletions engine/atom_test.go
Original file line number Diff line number Diff line change
@@ -135,3 +135,16 @@ func TestAtom_Unparse(t *testing.T) {
}, tokens)
})
}

func TestAtom_Compare(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

assert.Equal(t, int64(-1), Atom("a").Compare(&m, nil))
assert.Equal(t, int64(-1), Atom("a").Compare(Atom("b"), nil))
assert.Equal(t, int64(0), Atom("a").Compare(Atom("a"), nil))
assert.Equal(t, int64(1), Atom("b").Compare(Atom("a"), nil))
assert.Equal(t, int64(1), Atom("a").Compare(Variable("X"), nil))
assert.Equal(t, int64(1), Atom("a").Compare(Float(0), nil))
assert.Equal(t, int64(1), Atom("a").Compare(Integer(0), nil))
}
Loading