Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between csymf and csym in prolog

I am very confused what is the difference between csymf and csym in prolog, when I am using

?-code_type(X,csym).

X = 48 ;
X = 49 ;
....

?-code_type(X,csymf).

X = 65;
X = 66;
....

Would you please someone tell me what X should be exactly, I read the manual of SWI-prolog in this part and it is mentioned that

csym :Char is a letter (upper- or lowercase), digit or the underscore (_). These are valid C and Prolog symbol characters.

csymf :Char is a letter (upper- or lowercase) or the underscore (_). These are valid first characters for C and Prolog symbols.

So would you please provide me with some examples ?

Thanks

like image 928
Yasmin Avatar asked Feb 27 '26 12:02

Yasmin


1 Answers

You already have found the relevant descriptions, that state that code_type(Code, Type) holds a relation between a character code and his classification.

I think the manual is a bit misleading, because Prolog symbols are different than C (or Java, to say) symbols. These latter can be described with a regular expression like [_a-zA-Z][_a-zA-Z0-9]*, equivalent to the readable descriptions you cite.

Then c9 is a valid C symbol, while 9c is not (a digit cant start a symbol).

To inspect all 'properties' of a character (I assume you are aware of differences between character code - an integer - and the encoded character - localized), you could use

?- char_type(v,T).
T = alnum ;
T = alpha ;
T = csym ;
T = csymf ;
T = ascii ;
T = graph ;
T = lower ;
T = lower('V') ;
T = to_lower('V') ;
T = to_upper(v) ;
false.

Then v could start a C symbol.

?- char_type('7',T).
T = alnum ;
T = csym ;
T = ascii ;
T = digit ;
T = graph ;
T = to_lower('7') ;
T = to_upper('7') ;
T = digit(7) ;
T = xdigit(7).

We miss csymf here, then 7 cannot start a C symbol.

To get all the characters that can start a C symbol, you could use

?- forall(char_type(X,csymf),write(X)).
ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzªµºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ
true.

I think your result could be different than mine, depending on your locale.

like image 163
CapelliC Avatar answered Mar 02 '26 13:03

CapelliC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!