1

I'm trying to unify variable X with '*' (including the quote marks, for a total of 3-symbol string) What I'm doing is a simple X='*'., but that results in X having the value *. If I go for X=''*''., the result is X=''*''. I'm confused, how can I achieve the '*'?

Marcin
  • 380
  • 3
  • 20

1 Answers1

2

If you truly want a string, you should use double-quotes:

X="'*'".

If you want to make a symbol, you can use

atom_codes( X, "'*'" ).
Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • This results in X being unified with the [39,42,39] list, I do realise that's the prolog representation of a string, but that's not what I was trying to achieve, I'd like X to be printed as '*'. It doesn't have to be a string, I just don't know what instruction should I use – Marcin Apr 26 '15 at 00:26
  • 1
    Thank you, `atom_codes(X, "'*'").` worked like a charm, it said I need to use character escape \, as in `X = '\'*\''` – Marcin Apr 26 '15 at 00:50