Re: "dict"ionary typing?
Michael Hendricks <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAFHuXuZswskgnsbycC1kGqTpDk19LufZnhoaGB2Qo_pgeH2CQg@mail.gmail.com> |
On Wed, Dec 4, 2013 at 9:09 PM, Richard A. O'Keefe <[email protected]>wrote: > Lee Naish had a functional preprocessor. > > I had one called 'funnel', which relied on declarations. > If a name/arity pair was declared as a function or if > there was a :- func [mod:]name/arity declaration, then > in a clause body > p(...,name(T1,...,Tn),...) > => > name(T1, ..., Tn, T0), > p(..., T0, ...) > > Of course, if anyone wants to add functional syntax > in Prolog, they _really_ need to look at Mercury, > which does not introduce special syntax for function > calls but relies on declarations. > I'll also describe my experience writing and working with functional syntax in Prolog. Jan may find it useful as he mulls over functional notation for V7. I really enjoy how library(func) allows one to use most predicates, without declaration, in a functional context. In this case, the $ operator (because math) does the heavy lifting. I find it powerful to be able to compose these predicates to form other, sometimes anonymous, predicates using the 'of' operator. I use function application in nearly all my Prolog code these days; mostly as a way to avoid variable name proliferation. I don't use function composition nearly as often as I thought I would. That's partly because Prolog doesn't yet have a rich library of functional building blocks like Haskell has. I also like the way that library(func) can use a variety of terms as if they were functions. For example, one obtains Python-style string interpolation by treating strings as functions. I dislike declarations when they can be inferred from usage. I particularly dislike function declarations in Prolog because they imply that a predicate can only be used as a function in a single "mode". One might reasonably use append/3 as a function in three different modes. I haven't implemented it yet, but I'm considering a new feature for library(func) inspired by Ciao's notation. Specifically, a single ~ marks the argument to be used as output for *this* call. ?- writeln(append([a,b],[c,d],~)). [a,b,c,d]. ?- length(List, ~ is 1 + 1). List = [_G1821, _G1824]. -- Michael -------------- next part -------------- HTML attachment scrubbed and removed