prolog, how to correctly use escape sequences

122 Views Asked by At

I need (for design choices) to obtain a list who respects the following pattern:

Uses = ['foo\/1', 'foobar\/2'].

I'm able to build up the name/number pattern doing:

all((P\/A), (rule(X, Ux, _, Module), member(U, Ux), U = (P/A)), Uses).

where rule is an internal fact and Ux is a list.

I can escape slashes easily, using the '/' shortcut, but what about putting (P/A) between quotes?

How do that? please help me.

2

There are 2 best solutions below

0
On BEST ANSWER

If you want to obtain 'foo/1', you can easily use atomic_list_concat/2 predicate as follows:

Functor=foo,
Arity=1,
atomic_list_concat([Functor, '/', Arity], Output).

In this way Output variable will be bound to 'foo/1' term.

0
On

Just put them between 3 apexes:

?- A=foo, B=1, writeln('''A/B''').
'A/B'
A = foo,
B = 1