# Tersifying Prolog

**URL:** <https://swi-prolog.discourse.group/t/tersifying-prolog/7148>\
**Category:** General\
**Created:** [January 6, 2024, 4:30pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148 "2024-01-06T16:30:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![emiruz](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emiruz/32/4495_2.png) [@emiruz](https://swi-prolog.discourse.group/u/emiruz)\
**Post date:** [January 6, 2024, 4:30pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/1 "2024-01-06T16:30:37Z")

</div>

I suspect that like many others I have a fetish for terse code 🙂 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 🙂

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?

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [January 6, 2024, 5:26pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/2 "2024-01-06T17:26:09Z")

</div>

What dost thou protest at? 😀

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

---

<div class="post-metadata">

**Author:** ![anon419083](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anon419083](https://swi-prolog.discourse.group/u/anon419083)\
**Post date:** [January 6, 2024, 5:43pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/3 "2024-01-06T17:43:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![emiruz](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emiruz/32/4495_2.png) [@emiruz](https://swi-prolog.discourse.group/u/emiruz)\
**Post date:** [January 6, 2024, 7:27pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/4 "2024-01-06T19:27:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon419083](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anon419083](https://swi-prolog.discourse.group/u/anon419083)\
**Post date:** [January 6, 2024, 7:31pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/5 "2024-01-06T19:31:11Z")

</div>

You were right then…

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [January 6, 2024, 7:52pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/6 "2024-01-06T19:52:02Z")

</div>

> [@emiruz](#):
>
> a lot of variable chaining

DCGs are one way of reducing the verbiage of variable chaining. (Also EDCGs, and @jan 's suggestion [Dealing with state - #10 by jan](https://swi-prolog.discourse.group/t/dealing-with-state/6866/10))

---

<div class="post-metadata">

**Author:** ![emiruz](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emiruz/32/4495_2.png) [@emiruz](https://swi-prolog.discourse.group/u/emiruz)\
**Post date:** [January 6, 2024, 9:08pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/7 "2024-01-06T21:08:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [January 7, 2024, 4:43pm UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/8 "2024-01-07T16:43:49Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![nobrowser](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/nobrowser/32/4269_2.png) [@nobrowser](https://swi-prolog.discourse.group/u/nobrowser)\
**Post date:** [January 8, 2024, 5:22am UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/9 "2024-01-08T05:22:24Z")

</div>

> [@ridgeworks](#):
>
> The practical question, at least for me, is how to easily enter these math symbols on a standard keyboard.

Compose key and a custom XCompose file. Standard on X11 😏

–  
Ian

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [January 8, 2024, 6:51am UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/10 "2024-01-08T06:51:40Z")

</div>

> [@emiruz](#):
>
> I’m not finding any help or documentation on “pushback lists”, what are they?

I’ve never used them but: [Push-back lists on DCG rule heads](https://swi-prolog.discourse.group/t/push-back-lists-on-dcg-rule-heads/6532)

> [@emiruz](#):
>
> Are there any newb friendly examples of Yan’s approach?

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:](https://swi-prolog.discourse.group/t/autum-challenge-short-deadfish-numbers/6869/5:)

> <https://gist.github.com/kamahen/35cdfde14d7dfbfc07ceceb5d97c8cd7>

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [January 8, 2024, 7:55am UTC](https://swi-prolog.discourse.group/t/tersifying-prolog/7148/11 "2024-01-08T07:55:00Z")

</div>

Slightly related, though in R, but actually written in Prolog 🙂

> **[mathml: Translate R Expressions to MathML and LaTeX](https://journal.r-project.org/articles/RJ-2023-073/)**
>
> This R package translates R objects to suitable elements in MathML or LaTeX, thereby allowing for a pretty mathematical representation of R objects and functions in data analyses, scientific reports and interactive web content. In the...

It automatically converts your `pbinom(k, N, p)` to something like _P_(_X_ ≤ _k_; _N_, _p_) in the output.
