Difficulty appending domains
Attempting to read a file and add domain constraints.
?- foldl(clpz:\/, [3..4,8..10,15..20],0..0,X).
error(syntax_error(incomplete_reduction),read_term/3:1).
workaround:
append_domains(C1,C2,C3):-
C3=C1\/C2.
?- foldl(append_domains, [3..4,8..10,15..20],0..0,X).
X = 15..20\/(8..10\/(3..4\/0..0))
I don't understand why folding \/ over a list doesn't work, or why it can't be used as an argument to call.
To quickly trace down the problem, apply declarative reasoning: Generalize the example to find shorter fragments that still exhibit the issue.
You can generalize the code and query by using variables instead of more concrete (sub-)terms.
Well, I'll attempt to do that;
Regardless of my lack of comprehension, I think it would be useful to library users to have some predicates to easily append domains like the fold example above. It must be a common or legitimate use case to add domains such as when one is reading them from a stream of some sort?
If such use cases arise, please post more about them, there may be better ways to solve them than simply adding the first predicate that seems useful in such a case.
- If something naturally has an appending relationship, it seems natural to support folds.
- In my particular case, I have extracted from https://www.unicode.org/Public/15.0.0/ucd/DerivedCoreProperties.txt the character code ranges for each row like:
0C2A..0C39 ; Alphabetic # Lo [16] TELUGU LETTER PA..TELUGU LETTER HA
0C3D ; Alphabetic # Lo TELUGU SIGN AVAGRAHA
```.
There could be hundreds of rows like that, so I'll read in those ranges, probably stick them in a list.
Then I want to relate a character code to the derived property like this:
'''prolog
char_code_alphabetic(Code, Property) :-
Code in 0x0c2a..0x0c39\/0x3cd\/...
'''
?- foldl(clpz:/, [3..4,8..10,15..20],0..0,X). error(syntax_error(incomplete_reduction),read_term/3:1).
Just to clarify this: This is first a syntactic problem. What you meant was probably clpz:(\/). But then, this is not a predicate. It is part of an expression used by (in)/2 only.
append_domains(C1,C2,C3):- C3=C1/C2.
?- foldl(append_domains, [3..4,8..10,15..20],0..0,X). X = 15..20/(8..10/(3..4/0..0))
Here you are constructing a term that might be used later on by (in)/2. Do you really want 0 to be part of it? In case you do, you can just write 0 in place of 0..0.