[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Escapes in Backquoted Strings

From: Daniel Diaz
Subject: Re: Escapes in Backquoted Strings
Date: Mon, 28 Mar 2011 09:34:39 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110223 Thunderbird/3.1.8


can you give me the exact error message for X = `\` ?
If it is
| ?- X = `\`.
uncaught exception: error(syntax_error('user_input:1 (char:8) _expression_ expected or previous operator needs brackets'),read_term/3)
it is due to the fact \ is also an operator and thus needs to be put inside ( ) as an argument of another operator (here it is =). Use instead:
| ?- X = (`\`).

X = \

Le 25/03/2011 21:38, Jan Burse a écrit :

Thank you, this explains a lot. So we have here
a feature (atom_no_escape) and a bug (X = `\`
not accepted).


Daniel Diaz schrieb:
  Hello Jan,

sorry for the late reply...

There is a flag to control the meaning of backquoted strings. By default
it is an atom without interpreting escape sequences.
But this can be changed (for more info see

Here is an example:

| ?- current_prolog_flag(back_quotes,X).

X = atom_no_escape

| ?- X=`\x61\`.

X = '\\x61\\'

| ?- set_prolog_flag(back_quotes,atom).

| ?- X=`\x61\`.

X = a

Hope this helps


Le 19/03/2011 18:32, Jan Burse a écrit :
Dear All

I am working with
    GNU Prolog 1.3.1
    By Daniel Diaz
    Copyright (C) 1999-2009 Daniel Diaz

It seems that escapes in backquoted strings are
detected, but not converted.

Normal single quotes:

  ?- X = 'abc'.
  X = abc
  | ?- X = '\''.
  X = ''''
  ?- X = '\x61\'.
  X = a

Back quotes:

  ?- X = `abc`.
  X = abc
  ?- X = `\'`.
  X = '\\'''
  ?- X = `\x61\`.
  X = '\\x61\\'

It seems that the escapes are not converted. But
they are detected during parsing of backquoted
strings, at least the first escaped character is
always expected:

  ?- X = `\`.
  uncaught exception: error(syntax_error('user_input:10 (char:8)
  _expression_ expected or previous operator needs brackets'),read_term/3)

But the closing escape character of a noctal or
hexadecimal constant seems not to be not expected:

  ?- X = `\x61`.
  X = '\\x61'.
  ?- X = `\0`.
  X = '\\0'

From my understanding of ISO standard for back quoted strings,
the same escaping rules should hold as for single quoted
strings. I am referening to non quote char (* *).

Is this a bug or a feature?


Ce message a été vérifié par MailScanner pour des virus ou des polluriels et rien de suspect n'a été trouvé.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]