Git Product home page Git Product logo

maplist-expander's Introduction

maplist-expander

Rationale

In Prolog, maplist is a great predicate that I try to use whenever applicable. Yet, there are two issues I identified:

  • At least in SICStus Prolog, maplist is slowed compared to writing the loop manually. When preparing benchmarks that uses maplist with an identity function, I observed 10-20x speed-ups when calling the loop instead.
  • There are only so many arities of maplist that are implemented (usually maplist/2 to maplist/4 - if, say, maplist/6 is needed, one has to write it oneself).

However, I still like using maplist. Using term expansion, an explicit recursion can be generated instead. This keeps the nice, clean looks of using maplist, yet gives us the performance and allows us to stop worrying about limited arities.

Usage

  • Drop maplist_expander.pl into your project.
  • Include the term expander by adding :- use_module(maplist_expander). to the top of your module.

Then, you're all set!

Limitations

  • Currently, this only works for SICStus Prolog. I might add a term expander for SWI Prolog in the future.
  • No expansion happens in combination with other meta-predicates (e.g., call).
  • It is not well-tested yet, so I hope you like experiments :-)

maplist-expander's People

Contributors

pkoerner avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.