multilines strings "a la python"

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

multilines strings "a la python"

Algaba
hello

  Desperately,  I need multilines strings "a la python", something like :

  a_predicate(""" this is a multiline
     without any requirement of being ended by \  or anything like
     that
     just like a copy/paste would love
""")

  Putting \n\ at the end of each line is a huge nuisance in copy/paste operations
  and
     largely unnatural compared with the solution that python and many other
     languages have reached.


  greetings.
algaba



_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: multilines strings "a la python"

Jose F. Morales
Hi,

Other Prolog systems support multiline strings also with "..." syntax. Does anyone remember if that is incompatible with ISO Prolog standard? If not, is there any reasonable syntax extension that can be adopted by other Prolog implementations too?

(I've included Ulrich Neumerkel in the discussion)

On Sat, Jan 31, 2015 at 12:35 PM, Algaba <[hidden email]> wrote:
hello

 Desperately,  I need multilines strings "a la python", something like :

 a_predicate(""" this is a multiline
    without any requirement of being ended by \  or anything like
    that
    just like a copy/paste would love
""")

 Putting \n\ at the end of each line is a huge nuisance in copy/paste operations
 and
    largely unnatural compared with the solution that python and many other
    languages have reached.


 greetings.
algaba



_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog



--
Jose

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: multilines strings "a la python"

Ulrich Neumerkel
((I am not sure that this will receive all recipients))

Jose F. Morales:

>Other Prolog systems support multiline strings also with "..." syntax. Does
>anyone remember if that is incompatible with ISO Prolog standard? If not,
>is there any reasonable syntax extension that can be adopted by other
>Prolog implementations too?
>
>(I've included Ulrich Neumerkel in the discussion)
>
>On Sat, Jan 31, 2015 at 12:35 PM, Algaba <[hidden email]> wrote:
>
>> hello
>>
>>  Desperately,  I need multilines strings "a la python", something like :
>>
>>  a_predicate(""" this is a multiline

This cannot be conforming Prolog syntax, that is, it cannot be a
syntax extension (5.5.1) as it interferes with valid Prolog syntax.
The minimal counterexample is probably:

:- set_prolog_flag(double_quotes,atom).

"""+"b. /*
"""*/

which corresponds to

+('',b).

With this extension, valid Prolog text would be interpreted
differently.

>>  Putting \n\ at the end of each line is a huge nuisance in copy/paste
>> operations

I add such text in Emacs with C-x r t \n\ Return
So spaces are added in lines that happen to be shorter.

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: multilines strings "a la python"

Algaba

El 31/01/15 19:48, Ulrich Neumerkel escribió:

> ((I am not sure that this will receive all recipients))
>
> Jose F. Morales:
>> Other Prolog systems support multiline strings also with "..." syntax. Does
>> anyone remember if that is incompatible with ISO Prolog standard? If not,
>> is there any reasonable syntax extension that can be adopted by other
>> Prolog implementations too?
>>
>> (I've included Ulrich Neumerkel in the discussion)
>>
>> On Sat, Jan 31, 2015 at 12:35 PM, Algaba <[hidden email]> wrote:
>>
>>> hello
>>>
>>>   Desperately,  I need multilines strings "a la python", something like :
>>>
>>>   a_predicate(""" this is a multiline
> This cannot be conforming Prolog syntax, that is, it cannot be a
> syntax extension (5.5.1) as it interferes with valid Prolog syntax.
> The minimal counterexample is probably:
>
> :- set_prolog_flag(double_quotes,atom).
>
> """+"b. /*
> """*/

I haven't used such example in my life, and probably I won't . If triple
double quotes is a problem, any other combination ( ''', !!!, {{{) would
be fine as well.

>
> which corresponds to
>
> +('',b).
>
> With this extension, valid Prolog text would be interpreted
> differently.
>
>>>   Putting \n\ at the end of each line is a huge nuisance in copy/paste
>>> operations
> I add such text in Emacs with C-x r t \n\ Return
> So spaces are added in lines that happen to be shorter.
Yes, I do create a macro that adds \n\ to the end of the line and then I
execute it n-times. But it's not nearly as easy as in
python.

greetings
...
algaba

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: multilines strings "a la python"

Ulrich Neumerkel
Algaba:
>> I add such text in Emacs with C-x r t \n\ Return
>> So spaces are added in lines that happen to be shorter.
>Yes, I do create a macro that adds \n\ to the end of the line and then I
>execute it n-times. But it's not nearly as easy as in
>python.

Putting \n\ directly at the end makes rather unreadable code.  But at
a fixed column position it is much better readable.  Look at the
following with a fixed-width font!

main_prog -->
    disclaimer,
    "                          \n\
main()               \n\
   {  int i;               \n\
      i = 3;               \n\
      if (i > 2)               \n\
        whatever();            \n\
      exit(0);               \n\
   }                           \n\
    ",
   footer.

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: multilines strings "a la python"

Jose F. Morales
On Sun, Feb 1, 2015 at 11:38 PM, Ulrich Neumerkel <[hidden email]> wrote:
Algaba:
>> I add such text in Emacs with C-x r t \n\ Return
>> So spaces are added in lines that happen to be shorter.
>Yes, I do create a macro that adds \n\ to the end of the line and then I
>execute it n-times. But it's not nearly as easy as in
>python.

Putting \n\ directly at the end makes rather unreadable code.  But at
a fixed column position it is much better readable.  Look at the
following with a fixed-width font!

main_prog -->
    disclaimer,
    "                          \n\
main()                         \n\
   {  int i;                   \n\
      i = 3;                   \n\
      if (i > 2)               \n\
        whatever();            \n\
      exit(0);                 \n\
   }                           \n\
    ",
   footer.

Unfortunately that text contains extra spaces which are not removed so that is not a solution in general. Would ISO allow using `...` as multiline string delimiter?

--
Jose

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: multilines strings "a la python"

Ulrich Neumerkel
Jose:
> Unfortunately that text contains extra spaces which are not removed so that
> is not a solution in general. Would ISO allow using `...` as multiline
> string delimiter?

What is the use case for having significant spaces at the end of a
line *and* the need to see the text structure verbatim.  This is
certaintly not the text of a programming language where only trailing
spaces are not significant except for continuation lines in strings.

The syntax of back quoted string (* 6.4.7 *) is defined already.  So
if you want an extension using them you have to use that syntax and
maybe only recognize a subset of it as a valid extension.  The syntax
is essentially the same of the double quoted list tokken (* 6.4.6 *)
and quoted token (* 6.4.2 *).

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: multilines strings "a la python"

Jose F. Morales
On Mon, Feb 2, 2015 at 9:45 AM, Ulrich Neumerkel <[hidden email]> wrote:
Jose:
> Unfortunately that text contains extra spaces which are not removed so that
> is not a solution in general. Would ISO allow using `...` as multiline
> string delimiter?

What is the use case for having significant spaces at the end of a
line *and* the need to see the text structure verbatim.  This is
certaintly not the text of a programming language where only trailing
spaces are not significant except for continuation lines in strings.

Sometimes trailing spaces really matter and as a programmer I would not like to add them if they are not needed, specially if the text in the string is not code (it may be HTML, css, SQL, etc.).
 
The syntax of back quoted string (* 6.4.7 *) is defined already.  So
if you want an extension using them you have to use that syntax and
maybe only recognize a subset of it as a valid extension.  The syntax
is essentially the same of the double quoted list tokken (* 6.4.6 *)
and quoted token (* 6.4.2 *).

The main issue raised by Algaba is that some modern programming languages realized that multiline strings for large pieces of verbatim text are useful (either as heredocs in shell, Python's """, or SWI's quasi quotation).

Assuming that multiline strings are really useful, is there any simple and ISO-compatible way to extend the syntax that Prolog implementations could follow?

--
Jose

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: multilines strings "a la python"

Algaba
In reply to this post by Ulrich Neumerkel
it's just a matter of ease of use, the simplest method by far is:
"""
text verbatim to be copied
"""

Since prolog is a great language for text processing, there are *lots*
of strings.
It's a bit contradictory not to have the easiest method for long
strings  in the toolset.


Having said this, I'll keep using gprolog, it's simply an inconvenience
to insert "\n\" back
and  forth.

El 02/02/15 09:45, Ulrich Neumerkel escribió:

> Jose:
>> Unfortunately that text contains extra spaces which are not removed so that
>> is not a solution in general. Would ISO allow using `...` as multiline
>> string delimiter?
> What is the use case for having significant spaces at the end of a
> line *and* the need to see the text structure verbatim.  This is
> certaintly not the text of a programming language where only trailing
> spaces are not significant except for continuation lines in strings.
>
> The syntax of back quoted string (* 6.4.7 *) is defined already.  So
> if you want an extension using them you have to use that syntax and
> maybe only recognize a subset of it as a valid extension.  The syntax
> is essentially the same of the double quoted list tokken (* 6.4.6 *)
> and quoted token (* 6.4.2 *).


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog