Abstract
Constraint Handling Rules (CHR) is usually compiled to logic programming languages. While there are implementations for imperative programming languages such as C and Java, its most popular host language remains Prolog. In this paper, we present Chr.js, a CHR system implemented in JavaScript, that is suitable for both the server-side and interactive client-side web applications. Chr.js provides (i) an interpreter, which is based on the asynchronous execution model of JavaScript, and (ii) an ahead-of-time compiler, resulting in synchronous constraint solvers with better performances. Because of the great popularity of JavaScript, Chr.js is the first CHR system that runs on almost all and even mobile devices, without the need for an additional runtime environment. As an example application we present the Chr.js Playground, an offline-capable web-interface which allows the interactive exploration of CHRs in every modern browser.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
List of languages that compile to JS, https://github.com/jashkenas/coffeescript/wiki/list-of-languages-that-compile-to-js.
- 2.
JSFiddle, https://jsfiddle.net/.
- 3.
SWISH, https://swish.swi-prolog.org/.
- 4.
The JavaScript language is standardised as ECMAScript [5]. The most recent version of the ECMAScript specification is the sixth version, often referred to as ES6 or ES2015 or by its codename Harmony. Although it defines TCO, it has not yet been implemented by the major browsers.
- 5.
For example the equality check in JavaScript is performed using == or === (type-safe), instead of the often used unification = in Prolog.
- 6.
PEG.js, https://pegjs.org/.
- 7.
A more detailed discussion on using synchronous or asynchronous functions is given in [15, Sect. 3.4].
- 8.
Travis Continuous Integration service, https://travis-ci.org/.
- 9.
Copy available at https://svn.ulyssis.org/repos/sipa/cchr/.
- 10.
Benchmarks available at https://github.com/fnogatz/CHR-Benchmarks.
- 11.
Chr.js provides a command line utility to pre-compile CHR programs: chrjs –optimized program.in.
References
Abdennadher, S., Krämer, E., Saft, M., Schmauss, M.: JaCK: a Java Constraint Kit. Electr. Notes Theoret. Comput. Sci. 64, 1–17 (2002)
Cantelon, M., Harter, M., Holowaychuk, T.J., Rajlich, N.: Node.js in Action. Manning Publications, Shelter Island (2017)
Crockford, D.: JavaScript: the world’s most misunderstood programming language. Douglas Crockford’s Javascript (2001)
Duck, G.J., Stuckey, P.J., de la Banda, M.G., Holzbaur, C.: The refined operational semantics of constraint handling rules. In: Demoen, B., Lifschitz, V. (eds.) ICLP 2004. LNCS, vol. 3132, pp. 90–104. Springer, Heidelberg (2004). https://doi.org/10.1007/978-3-540-27775-0_7
ECMAScript ECMA-Kommittee: A general purpose, cross-platform programming langugage, Standard ECMA-262 (1997)
Ford, B.: Parsing expression grammars: a recognition-based syntactic foundation. In: ACM SIGPLAN Notices, vol. 39, pp. 111–122. ACM (2004)
Frühwirth, T.: Constraint Handling Rules. Cambridge University Press, Cambridge (2009)
Frühwirth, T.: Constraint handling rules - what else? In: Bassiliades, N., Gottlob, G., Sadri, F., Paschke, A., Roman, D. (eds.) RuleML 2015. LNCS, vol. 9202, pp. 13–34. Springer, Cham (2015). https://doi.org/10.1007/978-3-319-21542-6_2
Gallaba, K., Mesbah, A., Beschastnikh, I.: Don’t call us, we’ll call you: characterizing callbacks in JavaScript. In: 2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM), pp. 1–10. IEEE (2015)
Ganz, S.E., Friedman, D.P., Wand, M.: Trampolined style. In: ACM SIGPLAN Notices, vol. 34, pp. 18–27. ACM (1999)
Holzbaur, C., Frühwirth, T.: Compiling constraint handling rules. In: ERCIM/COMPULOG Workshop on Constraints, CWI, Amsterdam (1998)
Holzbaur, C., Frühwirth, T.: Compiling constraint handling rules into prolog with attributed variables. In: Nadathur, G. (ed.) PPDP 1999. LNCS, vol. 1702, pp. 117–133. Springer, Heidelberg (1999). https://doi.org/10.1007/10704567_7
Holzbaur, C., Frühwirth, T.: A prolog constraint handling rules compiler and runtime system. Appl. Artif. Intell. 14(4), 369–388 (2000)
Lager, T., Wielemaker, J.: Pengines: web logic programming made easy. Theor. Pract. Logic Programm. 14(4–5), 539–552 (2014)
Nogatz, F.: CHR.js: compiling constraint handling rules to JavaScript. Master thesis, Ulm University, Germany (2015)
Nogatz, F., Seipel, D.: Implementing GraphQL as a query language for deductive databases in SWI-prolog using DCGs, quasi quotations, and dicts. In: Proceedings of 30th Workshop on Logic Programming (WLP 2016) (2016)
Schrijvers, T.: Analyses, optimizations and extensions of constraint handling rules. Ph.D. thesis, K.U. Leuven, Belgium, June 2005
Van Weert, P., Schrijvers, T., Demoen, B.: K.U. Leuven JCHR: a user-friendly, flexible and efficient CHR system for Java, pp. 47–62
Van Weert, P., Wuille, P., Schrijvers, T., Demoen, B.: CHR for imperative host languages. In: Schrijvers, T., Frühwirth, T. (eds.) Constraint Handling Rules. LNCS (LNAI), vol. 5388, pp. 161–212. Springer, Heidelberg (2008). https://doi.org/10.1007/978-3-540-92243-8_7
Wielemaker, J., Hendricks, M.: Why it’s nice to be quoted: quasiquoting for prolog. In: Proceedings of 23rd Workshop on Logic-based Methods in Programming Environments (WLPE) (2013)
Wielemaker, J., Lager, T., Riguzzi, F.: SWISH: SWI-prolog for sharing. In: Proceedings of the International Workshop on User-Oriented Logic Programming (IULP 2015) (2015)
Wolf, A.: Adaptive constraint handling with CHR in Java. In: Walsh, T. (ed.) CP 2001. LNCS, vol. 2239, pp. 256–270. Springer, Heidelberg (2001). https://doi.org/10.1007/3-540-45578-7_18
Wuille, P., Schrijvers, T., Demoen, B.: CCHR: the fastest CHR implementation. In: Proceedings of 4th Workshop on Constraint Handling Rules (CHR07), pp. 123–137 (2007)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2018 Springer Nature Switzerland AG
About this paper
Cite this paper
Nogatz, F., Frühwirth, T., Seipel, D. (2018). CHR.js: A CHR Implementation in JavaScript. In: Benzmüller, C., Ricca, F., Parent, X., Roman, D. (eds) Rules and Reasoning. RuleML+RR 2018. Lecture Notes in Computer Science(), vol 11092. Springer, Cham. https://doi.org/10.1007/978-3-319-99906-7_9
Download citation
DOI: https://doi.org/10.1007/978-3-319-99906-7_9
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-99905-0
Online ISBN: 978-3-319-99906-7
eBook Packages: Computer ScienceComputer Science (R0)