|
| 1 | + |
| 2 | +/* |
| 3 | + Testcases of all syntax variations. |
| 4 | + Everything that does not require cross-file scoping. |
| 5 | +*/ |
| 6 | + |
| 7 | +%============== Facts with all kinds of terms as parameters ========== |
| 8 | + |
| 9 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 10 | +% Integers and decimal numbers: |
| 11 | +a(0). % integer |
| 12 | +a(1.0). % decimal number |
| 13 | +a(1,0). % two arguments! |
| 14 | + |
| 15 | +% 2.15.1.5 Using digit groups in large integers |
| 16 | +% |
| 17 | +% SWI-Prolog supports splitting long integers into digit groups. |
| 18 | +% Digit groups can be separated with the sequence <underscore>, |
| 19 | +% <optional white space>. If the <radix> is 10 or lower, they |
| 20 | +% may also be separated with exactly one space. |
| 21 | +% http://www.swi-prolog.org/pldoc/man?section=digitgroupsyntax |
| 22 | +% The following all express the integer 1 million: |
| 23 | + |
| 24 | +a(1_000_000). |
| 25 | +a(1 000 000). |
| 26 | +a(1_000_/*more*/000). |
| 27 | + |
| 28 | + |
| 29 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 30 | +% 2.15.1.4 Syntax for non-decimal numbers |
| 31 | +% Edinburgh syntax: |
| 32 | +% <radix>'<number>, where <radix> is a number between 2 and 36. |
| 33 | +% ISO syntax: |
| 34 | +% 0[bxo]<number>. For example: A is 0b100 \/ 0xf00 is a valid expression. |
| 35 | +% http://www.swi-prolog.org/pldoc/man?section=nondecsyntax |
| 36 | + |
| 37 | +a(2'1010). % Edinburgh: binary representation of 10 |
| 38 | +a(8'12). % Edinburgh: octal representation of 10 |
| 39 | +a(16'A). % Edinburgh: hexadecimal representation of 10 |
| 40 | + |
| 41 | +%a(1'1). % Edinburgh: Illegal, radix must be above 1 |
| 42 | +% <-- Syntax error: Operator expected (is not the most helpful |
| 43 | +% <-- message but at least it is an error message |
| 44 | +%a(37'1). % Edinburgh: Illegal, radix must be below 37 |
| 45 | +% <-- Throws no error at this point but many lines below it will |
| 46 | +% <-- say: Syntax error: String too long (see style_check/1) |
| 47 | + |
| 48 | +a(0b1010). % ISO: binary representation of 10 |
| 49 | +a(0o12). % ISO: octal representation of 10 |
| 50 | +a(0xA). % ISO: hexadecimal representation of 10 |
| 51 | + |
| 52 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 53 | +% 2.15.1.2 Nested comments |
| 54 | +/* |
| 55 | + SWI-Prolog allows for nesting /* ... */ comments like this one |
| 56 | +*/ |
| 57 | +% http://www.swi-prolog.org/pldoc/man?section=nestedcomments |
| 58 | + |
| 59 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 60 | +% 2.15.1.3 Character Escape Syntax |
| 61 | +% Within quoted atoms special characters are represented using escape |
| 62 | +% sequences. An escape sequence is led in by the backslash (\) character. |
| 63 | +% Character escaping is only available if |
| 64 | +% current_prolog_flag(character_escapes, true) is active (default). |
| 65 | +% http://www.swi-prolog.org/pldoc/man?section=charescapes |
| 66 | + |
| 67 | +a('abc-\a\b\c\ |
| 68 | +\e\f\n\r\s\t\v-def'). |
| 69 | +% The code \xa\3 emits the character 10 (hexadecimal `a') followed by `3'. |
| 70 | +% Characters specified this way are interpreted as Unicode characters. See also \u. |
| 71 | +a('abc-\xa\3-def'). |
| 72 | +a('abc-\u1111-def'). |
| 73 | +%a('abc-\U11111111-def'). % Legal unicode sign in the Hangul character set |
| 74 | +%a('\U11111111'). % Legal unicode sign in the Hangul character set |
| 75 | +a('\40'). |
| 76 | +a('\\'). |
| 77 | +a('\"'). |
| 78 | +a('\''). |
| 79 | +a('\`'). |
0 commit comments