Tersifying Prolog

I suspect that like many others I have a fetish for terse code :slight_smile: So, every time I type “member”, “aggregate_all”, “findall” and so on, there’s a part of me which protests.

Partly inspired by reading @meditans code, I’m thinking about writing a little private “terse” library I put into everything so that I can write X ∈ Xs rather than member(X, Xs) or ∀(A,B) rather than forall(A,B), and so on. I’m not really concerned about how readable the code is for other people in this instance: its just for me :slight_smile:

I wondered if anyone has done this and what their experience was with it? Also I wondered if you’ve perhaps pursued a different route to the same goal?

1 Like

What dost thou protest at? :grinning:

Why wouldn’t “mem” or even “m”, instead of “member”, suffice for your shorthand?

It’s not about shorthand, I think. It’s more about how to mimic FOL formulae (or set notation) even more closely. So I understood it at least

No rhyme nor reason I guess – I just like maths notation, but anything much shorter than the current predicate names will do. prolog requires a lot of variable chaining so lines can get long pretty quickly.

You were right then…

DCGs are one way of reducing the verbiage of variable chaining. (Also EDCGs, and @jan 's suggestion Dealing with state - #10 by jan)

1 Like

I’m not finding any help or documentation on “pushback lists”, what are they?

DCGs make sense for some state related things (I think simplex package uses them well for example) . Are there any newb friendly examples of Yan’s approach?

Also user defined operators can be pretty effective at creating DSL’s within a Prolog framework. They would certainly be able to handle your small example. The practical question, at least for me, is how to easily enter these math symbols on a standard keyboard.

You seem to be mainly concerned with the choice of predicate names exported from libraries. Note that many of these names have been around for decades and the names mean something to most users. However, nothing prevents you from doing what you want either by wrapping the targeted predicates with a name of your choice or via goal expansion (at load time).

Compose key and a custom XCompose file. Standard on X11 :smirk:


Ian

I’ve never used them but: Push-back lists on DCG rule heads

Here is some code that uses @jan’s approach (it contains two versions of the code, with/without library(yall)), also mentioned here: https://swi-prolog.discourse.group/t/autum-challenge-short-deadfish-numbers/6869/5:

Slightly related, though in R, but actually written in Prolog :slight_smile:

It automatically converts your pbinom(k, N, p) to something like P(Xk; N, p) in the output.

1 Like