Advertisement

CHR.js: A CHR Implementation in JavaScript

  • Falco Nogatz
  • Thom Frühwirth
  • Dietmar Seipel
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11092)

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.

Keywords

Constraint handling rules JavaScript Compiler 

References

  1. 1.
    Abdennadher, S., Krämer, E., Saft, M., Schmauss, M.: JaCK: a Java Constraint Kit. Electr. Notes Theoret. Comput. Sci. 64, 1–17 (2002)CrossRefGoogle Scholar
  2. 2.
    Cantelon, M., Harter, M., Holowaychuk, T.J., Rajlich, N.: Node.js in Action. Manning Publications, Shelter Island (2017)Google Scholar
  3. 3.
    Crockford, D.: JavaScript: the world’s most misunderstood programming language. Douglas Crockford’s Javascript (2001)Google Scholar
  4. 4.
    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_7CrossRefGoogle Scholar
  5. 5.
    ECMAScript ECMA-Kommittee: A general purpose, cross-platform programming langugage, Standard ECMA-262 (1997)Google Scholar
  6. 6.
    Ford, B.: Parsing expression grammars: a recognition-based syntactic foundation. In: ACM SIGPLAN Notices, vol. 39, pp. 111–122. ACM (2004)Google Scholar
  7. 7.
    Frühwirth, T.: Constraint Handling Rules. Cambridge University Press, Cambridge (2009)Google Scholar
  8. 8.
    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_2CrossRefGoogle Scholar
  9. 9.
    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)Google Scholar
  10. 10.
    Ganz, S.E., Friedman, D.P., Wand, M.: Trampolined style. In: ACM SIGPLAN Notices, vol. 34, pp. 18–27. ACM (1999)Google Scholar
  11. 11.
    Holzbaur, C., Frühwirth, T.: Compiling constraint handling rules. In: ERCIM/COMPULOG Workshop on Constraints, CWI, Amsterdam (1998)Google Scholar
  12. 12.
    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_7CrossRefGoogle Scholar
  13. 13.
    Holzbaur, C., Frühwirth, T.: A prolog constraint handling rules compiler and runtime system. Appl. Artif. Intell. 14(4), 369–388 (2000)CrossRefGoogle Scholar
  14. 14.
    Lager, T., Wielemaker, J.: Pengines: web logic programming made easy. Theor. Pract. Logic Programm. 14(4–5), 539–552 (2014)CrossRefGoogle Scholar
  15. 15.
    Nogatz, F.: CHR.js: compiling constraint handling rules to JavaScript. Master thesis, Ulm University, Germany (2015)Google Scholar
  16. 16.
    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)Google Scholar
  17. 17.
    Schrijvers, T.: Analyses, optimizations and extensions of constraint handling rules. Ph.D. thesis, K.U. Leuven, Belgium, June 2005Google Scholar
  18. 18.
    Van Weert, P., Schrijvers, T., Demoen, B.: K.U. Leuven JCHR: a user-friendly, flexible and efficient CHR system for Java, pp. 47–62Google Scholar
  19. 19.
    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_7CrossRefGoogle Scholar
  20. 20.
    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)Google Scholar
  21. 21.
    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)Google Scholar
  22. 22.
    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_18CrossRefGoogle Scholar
  23. 23.
    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)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2018

Authors and Affiliations

  1. 1.Department of Computer ScienceUniversity of WürzburgWürzburgGermany
  2. 2.Institute of Software Engineering and Programming LanguagesUlm UniversityUlmGermany

Personalised recommendations