Re: Ann: SWI-Prolog 7.1.0
Michael Hendricks <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAFHuXuZepQVWen69zkSX1OkFBqxpvH8utasN97h8ciL70HeF-g@mail.gmail.com> |
On Sat, Dec 7, 2013 at 7:54 AM, Jan Wielemaker <[email protected]> wrote: > On 12/07/2013 02:48 PM, Michael Hendricks wrote: > > Is there an efficient term_tag(+Term, -Tag:atom) predicate so we can > > manually perform this optimization when wanted? > > > > do(X) :- > > term_tag(X, Tag), > > do_(Tag, X). > > do_(Tag, X) :- > > ... > > Funny enough, this was also proposed by Nicos under the name > term_type/2. It might make sense, especially of a variable > would leave the type unbound as well (just like term_hash/2). > > Opinions? > I prefer the name Nicos suggested. I have only a weak preference on how unbound variables are handled. If Type is left unbound like term_hash/2, I suspect that most of my term_type/2 usage will be like: term_type(Term, Type0), ( var(Type0) -> Type=var; Type=Type0 ), do(Type, ...) I typically only use defaulty data structures as sugar for high level, user facing APIs. The first clause of those APIs typically starts with var(X), !, ... My preference is weak because I don't use this construct often and it's only an optimization (although a nice one). I don't mind reading an extra line of code in those circumstances. Especially if other term_type/2 users prefer to leave Type unbound. -- Michael -------------- next part -------------- HTML attachment scrubbed and removed