term_to_atom and the '@' sign.

36 views
Skip to first unread message

Ben Engbers

unread,
Oct 17, 2018, 6:54:17 PM10/17/18
to SWI-Prolog
Hi,

The last year, I did neither have much time to play with Prolog nor time to follow the forum so I may have missed if this behaviour has been reported before.

In a program I wrote, I used this construct to create a search string that could be passed to xpath/3

 atomic_list_concat([Name, '(@type)'], Field), % Name: 'from' or 'to'
        term_to_atom
(Search1, Field),
        xpath
(Step, Search1, Type).

The last time that I used this program was probably january 2018 and at that time this still worked.

If I now try to run my code, these lines return an error.

?- Name = 'from', atomic_list_concat([Name, '(@type)'], Field),                                                                                               term_to_atom(Search1, Field).
ERROR
: Syntax error: Operator expected
ERROR
: from(
ERROR
: ** here **
ERROR
: @type) .

After deleting the @, I get this:

?- Name = 'from', atomic_list_concat([Name, '(type)'], Field),                                                                                                term_to_atom(Search1, Field).
Name = from,
Field = 'from(type)',
Search1 = from(type).

The search-string for xpath needs to contain the @.

My question is, did I make an error ( I am not that much experienced in Prolog) or is this a bug?

I can't remember when it was the last time that I upgraded Swipl but now I am using SWI-Prolog (threaded, 64 bits, version 7.7.19-10-g8b9477530).

Ben

Paulo Moura

unread,
Oct 17, 2018, 7:03:08 PM10/17/18
to Ben Engbers, SWI-Prolog
You can always define the operator yourself. For example:

$ swipl
...
?- op(200, fy, (@)).
true.

?- Name = 'from', atomic_list_concat([Name, '(@type)'], Field), term_to_atom(Search1, Field).
Name = from,
Field = 'from(@type)',
Search1 = from(@type).

Cheers,
Paulo
> --
> You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

-----------------------------------------------------------------
Paulo Moura
Logtalk developer




Carlo Capelli

unread,
Oct 18, 2018, 1:11:48 AM10/18/18
to Ben Engbers, SWI-Prolog
Hi Ben

seems the operator @ is defined by library(xpath), maybe something has changed in your inclusion path definition:

?- [library(xpath)].

true.


?- Name = 'from', atomic_list_concat([Name, '(@type)'], Field), term_to_atom(Search1, Field).

Name = from,

Field = 'from(@type)',

Search1 = from(@type).


HTH, Carlo



--

Ben Engbers

unread,
Oct 18, 2018, 5:04:36 AM10/18/18
to SWI-Prolog
Hi Paulo,

I never before had any need to define an operator so this didn't come into my mind. It works!

Thanx

Ben
PS. After reading all the discussions on Logtalk, I started looking at it myself. At first sight it looks promising!
Long, long time ago I changed from using Fortran to Java and using object orientation was a real paradigm-shift to me. Then I started using Prolog and that was the second shift. I am looking forward to see what benefits Logtalk will bring!

Op donderdag 18 oktober 2018 01:03:08 UTC+2 schreef Paulo Moura:
You can always define the operator yourself. For example:

$ swipl
...
?- op(200, fy, (@)).
true.

?- Name = 'from', atomic_list_concat([Name, '(@type)'], Field), term_to_atom(Search1, Field).
Name = from,
Field = 'from(@type)',
Search1 = from(@type).

Cheers,
Paulo


Ben Engbers

unread,
Oct 18, 2018, 5:17:32 AM10/18/18
to SWI-Prolog
Hi Carlo,

I didn't change anything to the/my Prolog-code itself. After upgrading Fedora 26 to Fedora 28, I restored from the backup and then I reinstalled Prolog. I can't remember if I explicitly tested my program at that time.

Maybe that Jan knows if anything else did change?

Cheers,
Ben

Op donderdag 18 oktober 2018 07:11:48 UTC+2 schreef cc.carlo.cap:

Jan Wielemaker

unread,
Oct 18, 2018, 6:39:05 AM10/18/18
to Ben Engbers, SWI-Prolog
On 18/10/2018 11:17, Ben Engbers wrote:
> Maybe that Jan knows if anything else did change?

Old versions loaded teh graphics system (xpce) by default into the
global space, providing the @ and ? operators. New versions do not
do that any longer, avoiding polution of user space and differences
with versions running in a non-graphical environment.

Cheers --- Jan

Ben Engbers

unread,
Oct 18, 2018, 6:51:44 AM10/18/18
to SWI-Prolog
Thanx for the extra information.

Cheers,
Ben

Op donderdag 18 oktober 2018 12:39:05 UTC+2 schreef Jan Wielemaker:
Reply all
Reply to author
Forward
0 new messages