Skip to main content

CHR.js: A CHR Implementation in JavaScript

  • Conference paper
  • First Online:
Book cover Rules and Reasoning (RuleML+RR 2018)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 11092))

Included in the following conference series:

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    List of languages that compile to JS, https://github.com/jashkenas/coffeescript/wiki/list-of-languages-that-compile-to-js.

  2. 2.

    JSFiddle, https://jsfiddle.net/.

  3. 3.

    SWISH, https://swish.swi-prolog.org/.

  4. 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. 5.

    For example the equality check in JavaScript is performed using == or === (type-safe), instead of the often used unification = in Prolog.

  6. 6.

    PEG.js, https://pegjs.org/.

  7. 7.

    A more detailed discussion on using synchronous or asynchronous functions is given in [15, Sect. 3.4].

  8. 8.

    Travis Continuous Integration service, https://travis-ci.org/.

  9. 9.

    Copy available at https://svn.ulyssis.org/repos/sipa/cchr/.

  10. 10.

    Benchmarks available at https://github.com/fnogatz/CHR-Benchmarks.

  11. 11.

    Chr.js provides a command line utility to pre-compile CHR programs: chrjs –optimized program.in.

References

  1. Abdennadher, S., Krämer, E., Saft, M., Schmauss, M.: JaCK: a Java Constraint Kit. Electr. Notes Theoret. Comput. Sci. 64, 1–17 (2002)

    Article  Google Scholar 

  2. Cantelon, M., Harter, M., Holowaychuk, T.J., Rajlich, N.: Node.js in Action. Manning Publications, Shelter Island (2017)

    Google Scholar 

  3. Crockford, D.: JavaScript: the world’s most misunderstood programming language. Douglas Crockford’s Javascript (2001)

    Google Scholar 

  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_7

    Chapter  Google Scholar 

  5. ECMAScript ECMA-Kommittee: A general purpose, cross-platform programming langugage, Standard ECMA-262 (1997)

    Google Scholar 

  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. Frühwirth, T.: Constraint Handling Rules. Cambridge University Press, Cambridge (2009)

    Google Scholar 

  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_2

    Chapter  Google Scholar 

  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. Ganz, S.E., Friedman, D.P., Wand, M.: Trampolined style. In: ACM SIGPLAN Notices, vol. 34, pp. 18–27. ACM (1999)

    Google Scholar 

  11. Holzbaur, C., Frühwirth, T.: Compiling constraint handling rules. In: ERCIM/COMPULOG Workshop on Constraints, CWI, Amsterdam (1998)

    Google Scholar 

  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_7

    Chapter  Google Scholar 

  13. Holzbaur, C., Frühwirth, T.: A prolog constraint handling rules compiler and runtime system. Appl. Artif. Intell. 14(4), 369–388 (2000)

    Article  Google Scholar 

  14. Lager, T., Wielemaker, J.: Pengines: web logic programming made easy. Theor. Pract. Logic Programm. 14(4–5), 539–552 (2014)

    Article  Google Scholar 

  15. Nogatz, F.: CHR.js: compiling constraint handling rules to JavaScript. Master thesis, Ulm University, Germany (2015)

    Google Scholar 

  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. Schrijvers, T.: Analyses, optimizations and extensions of constraint handling rules. Ph.D. thesis, K.U. Leuven, Belgium, June 2005

    Google Scholar 

  18. Van Weert, P., Schrijvers, T., Demoen, B.: K.U. Leuven JCHR: a user-friendly, flexible and efficient CHR system for Java, pp. 47–62

    Google Scholar 

  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_7

    Chapter  Google Scholar 

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

    Chapter  Google Scholar 

  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 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Falco Nogatz .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics