# Path: pyke/contexts.py
# class simple_context(object):
# class bc_context(simple_context):
# class variable(pattern.pattern):
# class anonymous(variable):
#     def __init__(self):
#     def dump(self):
#     def bind(self, var_name, var_context, val, val_context = None):
#     def is_bound(self, var):
#     def lookup_data(self, var_name, allow_vars = False, final = None):
#     def lookup(self, var, allow_variable_in_ans = False):
#     def mark(self, save_all_undo = False):
#     def end_save_all_undo(self):
#     def undo_to_mark(self, mark, *var_names_to_undo):
#     def done(self):
#     def _unbind(self, var_name):
#     def __init__(self, rule):
#     def name(self): return self.rule.name
#     def __repr__(self):
#     def create_plan(self, final = None):
#     def __new__(cls, name):
#     def __init__(self, name):
#     def __repr__(self): return '$' + self.name
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def simple_match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):
#     def __init__(self, name):
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):


import itertools
    import doctest
    import sys
from pyke import contexts
'''


class selector(object):
    def __init__(self):
        self.all = []           # [(pat_context, pattern, link)...]
        self.full_vars = []     # [(pat_context, pattern, [link])...]
        self.partial_vars = []  # [(pat_context, pattern, [link])...]
        self.data = {}          # {data: [link]}
    def add(self, pat_context, pattern, link):
        self.all.append((pat_context, pattern, link))
        if pattern.is_data(pat_context):
            self.data.set_default(pattern.as_data(pat_context), []).append(link)
        else:
            self.vars # FIX ??
    def gen_subset(self, pat_context, pattern):
        ''' yields links without binding any pattern variables.
        '''
        if pattern.is_data(pat_context):
            for link in self.data[pattern.as_data(pat_context)]: yield link
        else:
            for p_c, p, links in self.full_vars:
                for link in links: yield link
            if not isinstance(pattern, contexts.variable):
                self.partial_vars # FIX subsets
    def gen_match(self, pat_context, pattern):
        ''' yields links binding pattern variables.
        '''
        if pattern.is_data(pat_context):
            for link in self.data[pattern.as_data(pat_context)]: yield link

# Path: pyke/contexts.py
# class simple_context(object):
# class bc_context(simple_context):
# class variable(pattern.pattern):
# class anonymous(variable):
#     def __init__(self):
#     def dump(self):
#     def bind(self, var_name, var_context, val, val_context = None):
#     def is_bound(self, var):
#     def lookup_data(self, var_name, allow_vars = False, final = None):
#     def lookup(self, var, allow_variable_in_ans = False):
#     def mark(self, save_all_undo = False):
#     def end_save_all_undo(self):
#     def undo_to_mark(self, mark, *var_names_to_undo):
#     def done(self):
#     def _unbind(self, var_name):
#     def __init__(self, rule):
#     def name(self): return self.rule.name
#     def __repr__(self):
#     def create_plan(self, final = None):
#     def __new__(cls, name):
#     def __init__(self, name):
#     def __repr__(self): return '$' + self.name
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def simple_match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):
#     def __init__(self, name):
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):


# Path: experimental/cache_args.py
import itertools
    import doctest
    import sys
from pyke import contexts

'''


class selector(object):
    def __init__(self):
        self.all = []           # [(pat_context, pattern, link)...]
        self.full_vars = []     # [(pat_context, pattern, [link])...]
        self.partial_vars = []  # [(pat_context, pattern, [link])...]
        self.data = {}          # {data: [link]}
    def add(self, pat_context, pattern, link):
        self.all.append((pat_context, pattern, link))
        if pattern.is_data(pat_context):
            self.data.set_default(pattern.as_data(pat_context), []).append(link)
        else:
            self.vars # FIX ??
    def gen_subset(self, pat_context, pattern):
        ''' yields links without binding any pattern variables.
        '''
        if pattern.is_data(pat_context):
            for link in self.data[pattern.as_data(pat_context)]: yield link
        else:
            for p_c, p, links in self.full_vars:
                for link in links: yield link
            if not isinstance(pattern, contexts.variable):
                self.partial_vars # FIX subsets
    def gen_match(self, pat_context, pattern):
        ''' yields links binding pattern variables.
        '''
        if pattern.is_data(pat_context):
            for link in self.data[pattern.as_data(pat_context)]: yield link

        elif isinstance(pattern, contexts.variable):