1

One of my art projects is about visual aspects of Prolog terms. My current focus is on alignment / padding—not on syntactic variations1.

Let's assume I have something like write_tokens....

Between which tokens may I insert additional whitespace characters?

My (semi-educated) guess is this:

Everywhere except before open_ct tokens.

Is this it? Seems almost too easy:)

Thank you in advance!


Footnote 1: Syntactic variations (like [1] vs [1|[]]), semantic variations, variable name choices, redundancy elimination, highlighting using markup, font size / style / color are important issues in that project too, they're just not the focus of this question.

repeat
  • 18,496
  • 4
  • 54
  • 166
  • For those of of with the spec `open_ct` means something, but for others I am sure they are scratching their head. Maybe a link to [iso-prolog](https://stackoverflow.com/tags/iso-prolog/info) in addition to the provided tag. I am sure many here have never clicked on the `iso-prolog` tag. – Guy Coder Apr 26 '19 at 00:20
  • What about prefix operators? e.g. `-1 = - 1. false.` – Guy Coder Apr 26 '19 at 01:38
  • 1
    Do not forget about layout that you can insert *within* a token! – false Apr 26 '19 at 05:56
  • @false. continuation escape sequences? or within integer constants? – repeat Apr 26 '19 at 07:09
  • @GuyCoder. These are called 'character code constants' and are defined in "6.4.4 integer numbers" (6 syntax, 6.4 tokens). – repeat Apr 26 '19 at 07:14
  • @GuyCoder. `-1` vs `- 1`: good point! however, inserting spaces in between would not have come to my mind. this question is only about going from a term to tokens to a character string, not vice versa. – repeat Apr 26 '19 at 07:17
  • @GuyCoder. you are right that the question needs to be refined. (the audience is limited either way.) – repeat Apr 26 '19 at 07:20
  • @GuyCoder. whatabout swi? It's sure on my list, but not on the top. cf. [Mt 6,24](https://en.m.wikipedia.org/wiki/Matthew_6:24) – repeat Apr 26 '19 at 07:25
  • 1
    @repeat: E.g., `[ /* */ ]` – false Apr 26 '19 at 10:02
  • @false. Ok, of course the same with curly braces. Also (though not whitespace) superfluous brackets. It never ends... but that ain't no reason not to start:) – repeat Apr 26 '19 at 10:11
  • 1
    The brackets are separate tokens, there is no layout within tokens. The issue is that some atomic Prolog terms are printed as more than one token. – jschimpf Apr 26 '19 at 11:37
  • @jschimpf. You are right, of course;) My mind was just meandering around the greater theme 'on the readability of some terms.' The idea I had there is this: suppose we have three terms, `(1 + 2) * 3`, `3 * 4 + 5`, and `(3 + 4) * 7` which we want to print in three lines. Depending on the circumstances (bad light, long day, tired eyes ...), it might be advantageous to display superfluous brackets for the second term instead of spaces if the operands are to be in the spotlight, not the operators and their relative precedences. (I'm hoping that makes a bit more sense now.) – repeat Apr 26 '19 at 13:21

0 Answers0