Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:26:04+00:00 2026-05-24T10:26:04+00:00

Is there a Prolog implementation or library that caches predicates? Or would you implement

  • 0

Is there a Prolog implementation or library that caches predicates?

Or would you implement a, say, FIFO cache using assertz/1 and retract/1, like this:

:- dynamic cache/1.
ccall(G) :- cache(G).
ccall(G) :-
    \+ cache(G),
    call(G),
    ( findall(G0,cache(G0),Gs), length(Gs,N), N =:= 100 -> once retract(cache(_)) ; true ),
    assertz(cache(G)).

In ECLiPSe-CLP, one could at least replace the findall/3 line using extra-logical variables:

...
( getval(cache_size) =:= 100 -> once retract(cache(_)) ; incval(cache_size) ),
...

On my box, 1000 calls to this ccall/1 take >4.00 cpu sec, whereas the actual goal cpu time is negliglible (0.04 cpu sec).
So I guess a cache (particularly a LRU cache or so) implemented inside the interpreter would still outperform the assertz/1 and retract/1.

I don’t want to have caching for every predicate, of course, only for very few ones. A scenario could be like this: p([H|T], E) :- q(H,E) ; p(T,E) with q/2 having no side effects. p/2 is called for a steadily growing list but always/often for the same E.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:26:05+00:00Added an answer on May 24, 2026 at 10:26 am

    do you want tabling/memoization?
    XSB offers automatic tabling (you declare which predicates you want to have tabling)

    and yes, assertz/1 etc are kinda slow

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a lack of some predicates in one Prolog implementations, that are available
Is there a way to recursively redefine (don't know the technical term) prolog predicates?
Certain kinds of domain logic are represented more naturally using Prolog predicates than C#
With SWI Prolog, there's a predicate that finds the nth item in a list
Is there any reason why someone would need an XML prolog in an HTML5
There are some special operators in Prolog, one of them is is , however,
There is a conversion process that is needed when migrating Visual Studio 2005 web
Is there any way to define constants in prolog? I'd like to write something
There is a wonderful problem set called Ninety-Nine Prolog Problems . Problem P70 is
Is there a way to do an if in prolog, e.g. if a variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.