2

I have a string that I want to convert to a list:

"a + b = c"

I need it in list format to pass it onto to a member rule. When I pass it onto the member rule directly, it passes as a series of numbers which I assume is their character code, but I want the actual characters instead. How do I make it into a list then use it with a rule. I'm a novice in Prolog so I would appreciate any help.

CSharpFiasco
  • 204
  • 3
  • 8
  • 1
    The list of numbers are (as you assumed) "character codes", or just "codes". What you want are probably one-character atoms, or "chars". Look in the documentation for predicates that convert between these. –  Sep 22 '15 at 07:36

1 Answers1

1

SWI-Prolog has string_chars/2, but you can obtain the same using 2 ISO conforming predicates

?- atom_codes(A, "a + b = c"), atom_chars(A, Cs).
A = 'a + b = c',
Cs = [a, ' ', +, ' ', b, ' ', =, ' ', c].
CapelliC
  • 59,646
  • 5
  • 47
  • 90