2

When you are querying a Prolog database, often you will use terms that start with an uppercase letter as your variables. However, let's say that one of the constraints on your query is that a person's location must be "Dallas", and you want to query all the information in the database who meet those specifications. How would do you correctly make sure that Dallas is not interpreted as a variable to store a value in, and is interpreted as a string instead, for usage as a constraint on the query?

Mr Prolog
  • 521
  • 1
  • 5
  • 4

1 Answers1

1

Just wrap Dallas into single quotes : 'Dallas'. Btw that that doesn't form a string but an atom. For example, in Swi-Prolog with default setup, a string would be:

?- X = "hello".
X = [104, 101, 108, 108, 111].

While an atom would be

?- X = 'hello'.
X = hello.

They both have their own set of predicates and their semantic.

m09
  • 7,490
  • 3
  • 31
  • 58
  • 1
    [More about double quotes](http://stackoverflow.com/questions/8264699/what-is-the-difference-between-and-in-prolog) – false Apr 06 '12 at 21:59