0

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.

ameyer
  • 13
  • 4
  • 1
    If I understand you correctly, If you leave off the escape and just use `P/A`, then you'll get something like `Uses = [foo/1, foobar/2]` without the quotes or escapes. But it depends upon what `rule` produces for `Ux`. The elements of `Ux` would need to be `blah/3` format (no quotes or escapes) as well. – lurker Jun 27 '13 at 18:11
  • 1
    `?- all(P\/A, member(P/A, [x,x/y,y]), L). L = [x\/y]` I think you should *not* work with atoms (i.e. quoted expressions). What's the purpose of `Uses` ? – CapelliC Jun 27 '13 at 18:22
  • Uses will contain the body of X, which is a predicate. Because of serialization requirement (JSON) every member of Uses should be compatible with the json TERM, and so putted between quotes. – ameyer Jun 28 '13 at 08:53

2 Answers2

0

Just put them between 3 apexes:

?- A=foo, B=1, writeln('''A/B''').
'A/B'
A = foo,
B = 1
Andrea Scarpino
  • 791
  • 6
  • 13
0

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.

Daniele T.
  • 16
  • 1
  • 2