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

  • Home
  • SEARCH
  • 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 948081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:11:09+00:00 2026-05-15T23:11:09+00:00

Using PyClips, I’m trying to build rules in Clips that dynamically retrieve data from

  • 0

Using PyClips, I’m trying to build rules in Clips that dynamically retrieve data from the Python interpreter. To do this, I register an external function as outlined in the manual.

The code below is a toy example of the problem. I’m doing this because I have an application with a large corpus of data, in the form of a SQL database, which I want to reason with using Clips. However, I don’t want to waste time converting all this data into Clips assertions, if I can simply “plug” Clips directly into Python’s namespace.

However, when I try to create the rule, I get an error. What am I doing wrong?

import clips

#user = True

#def py_getvar(k):
#    return globals().get(k)
def py_getvar(k):
    return True if globals.get(k) else clips.Symbol('FALSE')

clips.RegisterPythonFunction(py_getvar)

print clips.Eval("(python-call py_getvar user)") # Outputs "nil"

# If globals().get('user') is not None: assert something
clips.BuildRule("user-rule", "(neq (python-call py_getvar user) nil)", "(assert (user-present))", "the user rule")
#clips.BuildRule("user-rule", "(python-call py_getvar user)", "(assert (user-present))", "the user rule")

clips.Run()
clips.PrintFacts()
  • 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-15T23:11:10+00:00Added an answer on May 15, 2026 at 11:11 pm

    I received some help on the PyClips support group. The solution is to ensure your Python function returns a clips.Symbol object and use (test …) to evaluate functions in the LHS of rules. The use of Reset() also appears to be necessary to activate certain rules.

    import clips
    clips.Reset()
    
    user = True
    
    def py_getvar(k):
        return (clips.Symbol('TRUE') if globals().get(k) else clips.Symbol('FALSE'))
    
    clips.RegisterPythonFunction(py_getvar)
    
    # if globals().get('user') is not None: assert something
    clips.BuildRule("user-rule", "(test (eq (python-call py_getvar user) TRUE))",
                    '(assert (user-present))',
                    "the user rule")
    
    clips.Run()
    clips.PrintFacts()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
Using Yii, I want to delete all the rows that are not from today.
I am using a Python module ( PyCLIPS ) and Django 1.3. I want
Using jQuery UI Resizable I'm trying to prevent resizing based on various rules. The
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using rubular.com as a guide, I am trying to get this expression to work
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
Using import datetime in python, is it possible to take a formatted time/date string
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange

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.