Giter Site home page Giter Site logo

packages-chr's Introduction

				CHR for SWI-Prolog
				==================

Authors and license
====================

This package contains code  from  the   following  authors.  All code is
distributed under the SWI-Prolog  conditions   with  permission from the
authors.


	* Tom Schrijvers, K.U.Leuven	[email protected]
	* Christian Holzbaur		[email protected]
	* Jan Wielemaker 		[email protected]


Files and their roles:
======================

	# library(chr)			chr_swi.pl
	Make user-predicates and hooks for loading CHR files available
	to the user.

	# library(chr/chr_op)
	Include file containing the operator declaractions

	# library(chr/chr_translate)
	Core translation module.  Defines chr_translate/2.	

	# library(chr/chr_debug)
	Debugging routines, made available to the user through
	library(chr).  Very incomplete.
	
	# library(chr/hprolog)
	Compatibility to hProlog.  Should be abstracted.

	# library(chr/pairlist)
	Deal with lists of Name-Value.  Used by chr_translate.pl


Status
======

Work  in  progress.  The  compiler  source  (chr_translate.pl)  contains
various `todo' issues. The debugger is  almost non existent. Future work
should  improve  on   the   compatibility    with   the   reference  CHR
documentation. Details on loading CHR files are subject to change.

packages-chr's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

packages-chr's Issues

Rule firing although guard should fail

I am using the 32-bit-Version of SWI-Prolog 8.2.0 on Windows 10 64-bit.

In the attached file, testchr.txt (rename to .pl before running), running testit should lead to none of the CHR rules to be executed.

testit adds the constraint c2(_Addr) to the store. For c2_rule to fire, c1(Dest) must fail. The expected behaviour is for c1(Dest) not to fail, as Dest is unified with _Addr from the testit-call, which is a variable and not an integer. Thus, the expected behaviour is for c2_rule not to fire.

However, when running testit, we get the following output:

>swipl
Welcome to SWI-Prolog (threaded, 32 bits, version 8.2.0)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

1 ?- use_module(testchr).
true.

2 ?- testit.
c2_rule(_97180)
true.

3 ?-

The output c2_rule indicates that the rule c2_rule was indeed executed.

The example comes from a much larger CHR code-base, but has been distilled down to the minimal example. As soon as the rule c1_rule is removed, the system behaves as expected.

I have also attached an execution trace in testchr_trace.txt.

Some warnings in the test suite

I don't know whether these are expected or not.

In SWI Prolog 8.3.5, running the test suite and grepping for WARN in the file build/Testing/Temporary/LastTest.log:

CHR test suite.  To run all tests run ?- test.

Running scripts from Tests  swipl-devel_original/packages/chr/Tests/dense_int.chr
. swipl-devel_original/packages/chr/Tests/fibonacci.chr
. swipl-devel_original/packages/chr/Tests/leq.chr
. swipl-devel_original/packages/chr/Tests/passive_check2.chr
. swipl-devel_original/packages/chr/Tests/passive_check.chr
. swipl-devel_original/packages/chr/Tests/primes.chr
================================================================================
CHR compiler WARNING:
    `--> Heads will never match or guard will always fail in rule number 4 at swipl-devel_original/packages/chr/Tests/primes.chr:24.
        This rule will never fire!
================================================================================
================================================================================
CHR compiler WARNING:
    `--> All heads passive in rule number 4 at swipl-devel_original/packages/chr/Tests/primes.chr:24.
        This rule never fires. Please check your program.
================================================================================
. swipl-devel_original/packages/chr/Tests/trigger_no_active_occurrence.chr
. swipl-devel_original/packages/chr/Tests/zebra.chr
. done

All tests passed

Unexpected rule fired.

Hi,

For the following program

%% test.pl 
:- use_module(library(chr)).
:- chr_constraint c/2.

c(K,_I), c(K,_J) <=> writeln('rule 1 fired').
c(_I,K), c(_J,K) <=> writeln('rule 2 fired').
?- consult(["test.pl"]).
true.

?- c(X,Y).
rule 2 fired
c($VAR(X),$VAR(Y)).

Although the 2nd rule has two heads and I only added one constraint (c(X,Y)), the rule still fired.

This issue can be reproduced in Stable release - SWI-Prolog 8.4.1-1 for Microsoft Windows (64 bit), and Daily builds - swipl-w64-2022-01-31.exe (version 8.5.6-26-gee0b3fea1).

N.B. swish has no the same problem, but the constraint are not preserved, see https://swish.swi-prolog.org/p/unexpected_rule_fired.pl

Thanks.

The line number of "Undeclared constraint" is wrong when using `include`

The reproduce steps as follows.

  1. Create two files.

main.pl

:- debug.
:- use_module(library(chr)).
:- chr_constraint c/1.
:- include('test.pl').

test.pl

test0 :- true.
test :- do_test.







c(X,Y,Z) <=> true.  %% line number 10
  1. In REPL
?- consult(["main.pl"]).
================================================================================
CHR compiler ERROR: invalid syntax "c(_78356,_78358,_78360)".
    `--> Undeclared constraint _78370/_78372 in head of rule number 1 at e:/work-pl/prolog/code/include/main.pl:10.
	Constraint should be one of [c/1].
================================================================================
true.

Notice that the compiling error shows the wrong location main.pl:10. It is should be in test.pl:10.

Feature Request: Persistent constraint store in top-level

As already discussed in pull request #2 it is a common request to have a persistent constraint store in SWI's top-level. My suggestion was to have a new chr_option(persistent_store, OffOn). Unfortunately it is not enough to simply prevent the top-level's backtracking by changing the used b_setval into nb_setval for saving constraints.

@JanWielemaker already proposed some thoughts on this in #2:

If we want an incremental toplevel for CHR it might be better to see whether the normal Prolog toplevel could be changed from backtracking to a recursive loop. That is surely possible. Also there I'm not sure it is the right direction. I tend to prefer the SWISH toplevel which gives you a completely fresh environment for each query.

I am willing in implementing an alternative approach again, but I am not sure if the requested behaviour is ok for Jan and which would be the best starting point for implementation. Let's use this issue to track this down :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.