pub fn match_symbol<'a>(symbol: &MatchSymbol, list_item: &'a SafasCell) -> Result<(SmallVec<[MatchBinding; 1]>, &'a SafasCell), BindError> {
        if let (MatchSymbol::Nil, SafasCell::Nil) = (symbol, list_item) {
            // EndOfInput matches if the list is nil
            Ok((smallvec![], list_item))
        } else if let SafasCell::List(car, cdr) = list_item {
            // Match car against the symbol
            let mut bindings = smallvec![];

            use self::MatchSymbol::*;
            match symbol {
                Atom(atom_id)               => { if car.to_atom_id() != Some(*atom_id)              { return Err(BindError::SyntaxMatchFailed); } },
                Nil                         => { if !car.is_nil()                                   { return Err(BindError::SyntaxMatchFailed); } },
                String(string)              => { if car.string_value().as_ref() != Some(string)     { return Err(BindError::SyntaxMatchFailed); } },
                Char(chr)                   => { if car.char_value() != Some(*chr)                  { return Err(BindError::SyntaxMatchFailed); } },
                Number(number)              => { if car.number_value() != Some(*number)             { return Err(BindError::SyntaxMatchFailed); } },
                Boolean(val)                => { if car.bool_value() != Some(*val)                  { return Err(BindError::SyntaxMatchFailed); } }
                EndOfInput                  => { /* Matched implicitly */ },

                StatementBinding(atom_id)   => { bindings.push(MatchBinding::Statement(*atom_id, Arc::clone(car))); }
                SymbolBinding(atom_id)      => { bindings.push(MatchBinding::Symbol(*atom_id, Arc::clone(car))); }

                List(list_pattern)  => {
                    let list_bindings = Self::match_with_symbols(list_pattern, &Arc::clone(car))?;
                    bindings.extend(list_bindings);
                }
            }

            Ok((bindings, &**cdr))
        } else {
            // List item is not a list
            Err(BindError::SyntaxMatchFailed)
        }
    }
///
/// Matches a single symbol, returning the bindings and the next item in the list if the match was successful
///
Matches a single symbol, returning the bindings and the next item in the list if the match was successful
Matches a single symbol returning the bindings and the next item in the list if the match was successful
pub fn match_symbol<'a>(symbol: &MatchSymbol, list_item: &'a SafasCell) -> Result<(SmallVec<[MatchBinding; 1]>, &'a SafasCell), BindError> {
        if let (MatchSymbol::Nil, SafasCell::Nil) = (symbol, list_item) {
            // EndOfInput matches if the list is nil
            Ok((smallvec![], list_item))
        } else if let SafasCell::List(car, cdr) = list_item {
            // Match car against the symbol
            let mut bindings = smallvec![];
            use self::MatchSymbol::*;
            match symbol {
                Atom(atom_id)               => { if car.to_atom_id() != Some(*atom_id)              { return Err(BindError::SyntaxMatchFailed); } },
                Nil                         => { if !car.is_nil()                                   { return Err(BindError::SyntaxMatchFailed); } },
                String(string)              => { if car.string_value().as_ref() != Some(string)     { return Err(BindError::SyntaxMatchFailed); } },
                Char(chr)                   => { if car.char_value() != Some(*chr)                  { return Err(BindError::SyntaxMatchFailed); } },
                Number(number)              => { if car.number_value() != Some(*number)             { return Err(BindError::SyntaxMatchFailed); } },
                Boolean(val)                => { if car.bool_value() != Some(*val)                  { return Err(BindError::SyntaxMatchFailed); } }
                EndOfInput                  => { /* Matched implicitly */ },
                StatementBinding(atom_id)   => { bindings.push(MatchBinding::Statement(*atom_id, Arc::clone(car))); }
                SymbolBinding(atom_id)      => { bindings.push(MatchBinding::Symbol(*atom_id, Arc::clone(car))); }
                List(list_pattern)  => {
                    let list_bindings = Self::match_with_symbols(list_pattern, &Arc::clone(car))?;
                    bindings.extend(list_bindings);
                }
            }
            Ok((bindings, &**cdr))
        } else {
            // List item is not a list
            Err(BindError::SyntaxMatchFailed)
        }
    }
pub fn match_symbol < ' a > ( symbol : & MatchSymbol , list_item : & ' a SafasCell ) -> Result < ( SmallVec < [ MatchBinding ; 1 ] > , & ' a SafasCell ) , BindError > { if let ( MatchSymbol :: Nil , SafasCell :: Nil ) = ( symbol , list_item ) { // EndOfInput matches if the list is nil Ok ( ( smallvec ! [ ] , list_item ) ) } else if let SafasCell :: List ( car , cdr ) = list_item { // Match car against the symbol let mut bindings = smallvec ! [ ] ; use self :: MatchSymbol :: * ; match symbol { Atom ( atom_id ) => { if car . to_atom_id ( ) != Some ( * atom_id ) { return Err ( BindError :: SyntaxMatchFailed ) ; } } , Nil => { if ! car . is_nil ( ) { return Err ( BindError :: SyntaxMatchFailed ) ; } } , String ( string ) => { if car . string_value ( ) . as_ref ( ) != Some ( string ) { return Err ( BindError :: SyntaxMatchFailed ) ; } } , Char ( chr ) => { if car . char_value ( ) != Some ( * chr ) { return Err ( BindError :: SyntaxMatchFailed ) ; } } , Number ( number ) => { if car . number_value ( ) != Some ( * number ) { return Err ( BindError :: SyntaxMatchFailed ) ; } } , Boolean ( val ) => { if car . bool_value ( ) != Some ( * val ) { return Err ( BindError :: SyntaxMatchFailed ) ; } } EndOfInput => { /* Matched implicitly */ } , StatementBinding ( atom_id ) => { bindings . push ( MatchBinding :: Statement ( * atom_id , Arc :: clone ( car ) ) ) ; } SymbolBinding ( atom_id ) => { bindings . push ( MatchBinding :: Symbol ( * atom_id , Arc :: clone ( car ) ) ) ; } List ( list_pattern ) => { let list_bindings = Self :: match_with_symbols ( list_pattern , & Arc :: clone ( car ) ) ? ; bindings . extend ( list_bindings ) ; } } Ok ( ( bindings , & * * cdr ) ) } else { // List item is not a list Err ( BindError :: SyntaxMatchFailed ) } }
Matches a single symbol, returning the bindings and the next item in the list if the match was successful
Matches a single symbol returning the bindings and the next item in the list if the match was successful
symbol
&MatchSymbol
list_item
&'a SafasCell
symbol
&MatchSymbol
list_item
&'a SafasCell