Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiban committed Mar 26, 2022
1 parent 9d71718 commit 62bc1b4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ $(go env GOPATH)/bin/1pl [<file>...]
- `X /\ Y`
- `X \/ Y`
- `\X`
- `X xor Y`
- `xor(X, Y)`

</details>

Expand Down
1 change: 1 addition & 0 deletions engine/compound.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func Seq(sep Atom, ts ...Term) Term {
return s
}

// Pair returns a pair of k and v.
func Pair(k, v Term) Term {
return &Compound{
Functor: "-",
Expand Down
4 changes: 2 additions & 2 deletions engine/dcg.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ func init() {
},
{Name: "->", Arity: 2}: func(args []Term, list, rest Term, env *Env) (Term, error) {
v := NewVariable()
if_, err := dcgBody(args[0], list, v, env)
cond, err := dcgBody(args[0], list, v, env)
if err != nil {
return nil, err
}
then, err := dcgBody(args[1], v, rest, env)
if err != nil {
return nil, err
}
return Atom("->").Apply(if_, then), nil
return Atom("->").Apply(cond, then), nil
},
}
}
Expand Down
15 changes: 15 additions & 0 deletions engine/exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,62 +44,77 @@ func (e *Exception) Error() string {
return buf.String()
}

// TypeErrorAtom returns a type error exception for atom.
func TypeErrorAtom(culprit Term) *Exception {
return TypeError("atom", culprit)
}

// TypeErrorAtomic returns a type error exception for atomic.
func TypeErrorAtomic(culprit Term) *Exception {
return TypeError("atomic", culprit)
}

// TypeErrorByte returns a type error exception for byte.
func TypeErrorByte(culprit Term) *Exception {
return TypeError("byte", culprit)
}

// TypeErrorCallable returns a type error exception for callable.
func TypeErrorCallable(culprit Term) *Exception {
return TypeError("callable", culprit)
}

// TypeErrorCharacter returns a type error exception for character.
func TypeErrorCharacter(culprit Term) *Exception {
return TypeError("character", culprit)
}

// TypeErrorCompound returns a type error exception for compound.
func TypeErrorCompound(culprit Term) *Exception {
return TypeError("compound", culprit)
}

// TypeErrorEvaluable returns a type error exception for evaluable.
func TypeErrorEvaluable(culprit Term) *Exception {
return TypeError("evaluable", culprit)
}

// TypeErrorInByte returns a type error exception for in_byte.
func TypeErrorInByte(culprit Term) *Exception {
return TypeError("in_byte", culprit)
}

// TypeErrorInCharacter returns a type error exception for in_character.
func TypeErrorInCharacter(culprit Term) *Exception {
return TypeError("in_character", culprit)
}

// TypeErrorInteger returns a type error exception for integer.
func TypeErrorInteger(culprit Term) *Exception {
return TypeError("integer", culprit)
}

// TypeErrorList returns a type error exception for list.
func TypeErrorList(culprit Term) *Exception {
return TypeError("list", culprit)
}

// TypeErrorNumber returns a type error exception for number.
func TypeErrorNumber(culprit Term) *Exception {
return TypeError("number", culprit)
}

// TypeErrorPredicateIndicator returns a type error exception for predicate_indicator.
func TypeErrorPredicateIndicator(culprit Term) *Exception {
return TypeError("predicate_indicator", culprit)
}

// TypeErrorPair returns a type error exception for pair.
func TypeErrorPair(culprit Term) *Exception {
return TypeError("pair", culprit)
}

// TypeErrorFloat returns a type error exception for float.
func TypeErrorFloat(culprit Term) *Exception {
return TypeError("float", culprit)
}
Expand Down
1 change: 1 addition & 0 deletions engine/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ func Tan(x Number) (Number, error) {
return Float(math.Tan(vx)), nil
}

// Xor returns the bitwise exclusive or of x and y.
func Xor(x, y Number) (Number, error) {
vx, ok := x.(Integer)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package prolog

import (
"context"
_ "embed"
_ "embed" // for go:embed
"errors"
"io"
"io/ioutil"
Expand Down

0 comments on commit 62bc1b4

Please sign in to comment.