-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature request time/1 and/or statistics/2 predicate #327
Comments
What are you going to achieve with Since As for |
In case I would need to write my own time/1 is usually bootstrapped from statistics/2, but bootstrapping different backtracking results, like here in SWI-Prolog:
A novice programmer doesn't know how to implement it. A predicate? It goes by the name |
You can define your own package main
import (
"fmt"
"time"
"github.com/ichiban/prolog"
"github.com/ichiban/prolog/engine"
)
func main() {
p := prolog.New(nil, nil)
p.Register1(engine.NewAtom("time"), func(vm *engine.VM, g engine.Term, k engine.Cont, env *engine.Env) *engine.Promise {
t := time.Now()
return engine.Call(vm, g, func(env *engine.Env) *engine.Promise {
fmt.Printf("time: %s\n", time.Now().Sub(t))
t = time.Now()
return k(env)
}, env)
})
p.Register1(engine.NewAtom("sleep"), func(_ *engine.VM, s engine.Term, k engine.Cont, env *engine.Env) *engine.Promise {
var d time.Duration
switch s := env.Resolve(s).(type) {
case engine.Variable:
return engine.Error(engine.InstantiationError(env))
case engine.Integer:
d = time.Duration(s) * time.Second
case engine.Float:
d = time.Duration(s * engine.Float(time.Second))
default:
return engine.Error(engine.TypeError(engine.NewAtom("number"), s, env))
}
time.Sleep(d)
return k(env)
})
sols, err := p.Query(`time((sleep(0.1);sleep(0.1))).`)
if err != nil {
panic(err)
}
for sols.Next() {
}
if err := sols.Close(); err != nil {
panic(err)
}
}
|
Would it be possible to have some time/1 and
statistics/2 predicate? Its not listed here:
https://github.com/ichiban/prolog/wiki
Which is understandable, since the ISO core
standard doesn't mention it. But how
about implementing it nevertheless since
many Prolog systems provide it now?
The text was updated successfully, but these errors were encountered: