3 ms·
If it was Erlang, the reason that Prolog would be considered a variable would be the initial caps. is and sweet would be atoms (which are like names or labels)
by pessimizer 13y ago
If it was Erlang, the reason that Prolog would be considered a variable would be the initial caps. is and sweet would be atoms (which are like names or labels) because of the lack of quotes and lack of initial caps. Prolog may convert atoms to strings when they're used in a string function (or that particular string function may convert atoms to strings.) Do they even call them functions in Prolog? Doesn't seem appropriate.
edit: also, single quotes in Erlang are a way of creating an initial cap atom, or an atom with special characters in it. Double quotes are used for strings. Might be the same.
edit: just checked, it's the same. And compound term?
- dangoldin 13y agoOP here - someone left a comment on the blog who's clearly more knowledgeable than I am. I'm copying it here: The quotes are necessary if an atom starts with something other than a lower-case character. Any unquoted token that starts with an upper-case letter is a variable. As for atomic_list_concat, it's an optimized library function that requires the separator. It's certainly possible to write an equivalent that is completely flexible.
- sltkr 13y agoI think the predicate you wanted to demonstrate is called append/3, which works on list (while concat applies to atoms). In Prolog, 'foo' constructs an atom, which is equivalent to foo without any quotes (but the quotes are useful to construct atoms with spaces, with digits, starting with a capital letter, etc.) However, if you want to manipulate atoms as text, you typically want to use strings instead, which are literally lists of character codes in Prolog, and can be entered as double quotes. For example, "ABC" = [65,66,67]. To convert between strings and atoms dynamically, use atom_chars/2. For example: ?- append("Prolog is", " awesome", Z), atom_chars(A,Z). Z = [80, 114, 111, 108, 111, 103, 32, 105, 115|...], A = 'Prolog is awesome'. ?- append("Prolog is", Y, "Prolog is awesome"), atom_chars(A,Y). Y = [32, 97, 119, 101, 115, 111, 109, 101], A = ' awesome'. ?- append(X, "is awesome", "Prolog is awesome"), atom_chars(A,X). X = [80, 114, 111, 108, 111, 103, 32], A = 'Prolog '.
- dangoldin 13y agoThanks for the explanation. It's such a neat idea that inputs and outputs can be interchangeable. Opens up approaches that are very different than the standard ones. The append predicate is definitely a better example so thanks for sharing.
- wwweston 13y ago> Do they even call them functions in Prolog? Doesn't seem appropriate. Nope. "Predicate" is the term you're looking for.