clpz icon indicating copy to clipboard operation
clpz copied to clipboard

Difficulty appending domains

Open dougransom opened this issue 4 months ago • 5 comments

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.

dougransom avatar Sep 06 '25 16:09 dougransom

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.

triska avatar Sep 06 '25 17:09 triska

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?

dougransom avatar Sep 06 '25 18:09 dougransom

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.

triska avatar Sep 06 '25 20:09 triska

  1. If something naturally has an appending relationship, it seems natural to support folds.
  2. 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\/...   
'''

dougransom avatar Sep 08 '25 19:09 dougransom

?- 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.

UWN avatar Sep 08 '25 19:09 UWN