pub fn lookup_external(
        &mut self,
        call_id: u64,
        instance: &Term,
        field: &Term,
    ) -> PolarResult<QueryEvent> {
        let (field_name, args, kwargs): (
            Symbol,
            Option<Vec<Term>>,
            Option<BTreeMap<Symbol, Term>>,
        ) = match self.deref(field).value() {
            Value::Call(Call { name, args, kwargs }) => (
                name.clone(),
                Some(args.iter().map(|arg| self.deep_deref(arg)).collect()),
                kwargs.as_ref().map(|unwrapped| {
                    unwrapped
                        .iter()
                        .map(|(k, v)| (k.to_owned(), self.deep_deref(v)))
                        .collect()
                }),
            ),
            Value::String(field) => (Symbol(field.clone()), None, None),
            v => {
                return Err(self.type_error(
                    &field,
                    format!("cannot look up field {:?} on an external instance", v),
                ))
            }
        };

        // add an empty choice point; lookups return only one value
        // but we'll want to cut if we get back nothing
        self.push_choice(vec![]);

        self.log_with(
            || {
                let mut msg = format!("LOOKUP: {}.{}", instance.to_string(), field_name);
                msg.push('(');
                let args = args
                    .clone()
                    .unwrap_or_else(Vec::new)
                    .into_iter()
                    .map(|a| a.to_polar());
                let kwargs = kwargs
                    .clone()
                    .unwrap_or_else(BTreeMap::new)
                    .into_iter()
                    .map(|(k, v)| format!("{}: {}", k, v.to_polar()));
                msg.push_str(&args.chain(kwargs).collect::<Vec<String>>().join(", "));
                msg.push(')');
                msg
            },
            &[],
        );

        Ok(QueryEvent::ExternalCall {
            call_id,
            instance: self.deep_deref(instance),
            attribute: field_name,
            args,
            kwargs,
        })
    }
/// Return an external call event to look up a field's value
/// in an external instance. Push a `Goal::LookupExternal` as
/// an alternative on the last choice point to poll for results.
Return an external call event to look up a field's value
in an external instance. Push a `Goal::LookupExternal` as
an alternative on the last choice point to poll for results.
Return an external call event to look up a field ' s value in an external instance . Push a ` Goal :: LookupExternal ` as an alternative on the last choice point to poll for results .
pub fn lookup_external(
        &mut self,
        call_id: u64,
        instance: &Term,
        field: &Term,
    ) -> PolarResult<QueryEvent> {
        let (field_name, args, kwargs): (
            Symbol,
            Option<Vec<Term>>,
            Option<BTreeMap<Symbol, Term>>,
        ) = match self.deref(field).value() {
            Value::Call(Call { name, args, kwargs }) => (
                name.clone(),
                Some(args.iter().map(|arg| self.deep_deref(arg)).collect()),
                kwargs.as_ref().map(|unwrapped| {
                    unwrapped
                        .iter()
                        .map(|(k, v)| (k.to_owned(), self.deep_deref(v)))
                        .collect()
                }),
            ),
            Value::String(field) => (Symbol(field.clone()), None, None),
            v => {
                return Err(self.type_error(
                    &field,
                    format!("cannot look up field {:?} on an external instance", v),
                ))
            }
        };
        // add an empty choice point; lookups return only one value
        // but we'll want to cut if we get back nothing
        self.push_choice(vec![]);
        self.log_with(
            || {
                let mut msg = format!("LOOKUP: {}.{}", instance.to_string(), field_name);
                msg.push('(');
                let args = args
                    .clone()
                    .unwrap_or_else(Vec::new)
                    .into_iter()
                    .map(|a| a.to_polar());
                let kwargs = kwargs
                    .clone()
                    .unwrap_or_else(BTreeMap::new)
                    .into_iter()
                    .map(|(k, v)| format!("{}: {}", k, v.to_polar()));
                msg.push_str(&args.chain(kwargs).collect::<Vec<String>>().join(", "));
                msg.push(')');
                msg
            },
            &[],
        );
        Ok(QueryEvent::ExternalCall {
            call_id,
            instance: self.deep_deref(instance),
            attribute: field_name,
            args,
            kwargs,
        })
    }
pub fn lookup_external ( & mut self , call_id : u64 , instance : & Term , field : & Term , ) -> PolarResult < QueryEvent > { let ( field_name , args , kwargs ) : ( Symbol , Option < Vec < Term > > , Option < BTreeMap < Symbol , Term > > , ) = match self . deref ( field ) . value ( ) { Value :: Call ( Call { name , args , kwargs } ) => ( name . clone ( ) , Some ( args . iter ( ) . map ( | arg | self . deep_deref ( arg ) ) . collect ( ) ) , kwargs . as_ref ( ) . map ( | unwrapped | { unwrapped . iter ( ) . map ( | ( k , v ) | ( k . to_owned ( ) , self . deep_deref ( v ) ) ) . collect ( ) } ) , ) , Value :: String ( field ) => ( Symbol ( field . clone ( ) ) , None , None ) , v => { return Err ( self . type_error ( & field , format ! ( " " v ) , ) ) } } ; // add an empty choice point; lookups return only one value // but we'll want to cut if we get back nothing self . push_choice ( vec ! [ ] ) ; self . log_with ( | | { let mut msg = format ! ( " " instance to_string ( ) field_name ) ; msg . push ( '(' ) ; let args = args . clone ( ) . unwrap_or_else ( Vec :: new ) . into_iter ( ) . map ( | a | a . to_polar ( ) ) ; let kwargs = kwargs . clone ( ) . unwrap_or_else ( BTreeMap :: new ) . into_iter ( ) . map ( | ( k , v ) | format ! ( " " k v to_polar ( ) ) ) ; msg . push_str ( & args . chain ( kwargs ) . collect :: < Vec < String > > ( ) . join ( " " ) ) ; msg . push ( ')' ) ; msg } , & [ ] , ) ; Ok ( QueryEvent :: ExternalCall { call_id , instance : self . deep_deref ( instance ) , attribute : field_name , args , kwargs , } ) }
Return an external call event to look up a field's value
in an external instance.
Return an external call event to look up a field ' s value in an external instance .
&mut self
call_id
u64
instance
&Term
field
&Term