pub fn new<SymbolList: IntoIterator<Item=(AtomId, Arc<SyntaxSymbol>)>>(syntax_symbols: SymbolList, imported_bindings: Arc<HashMap<usize, CellRef>>, extend_syntax: Option<CellRef>) -> SyntaxClosure {
        // Add the imported bindings into each syntax symbol to generate the syntax symbols list
        let mut bound_symbols: Vec<(u64, CellRef)>   = vec![];
        let mut all_symbols     = vec![];

        for (AtomId(symbol_id), symbol) in syntax_symbols.into_iter() {
            // Set the imported bindings for the symbol
            let mut symbol  = (*symbol).clone();
            symbol.imported_bindings = Arc::clone(&imported_bindings);
            let symbol      = Arc::new(symbol);

            // Turn into syntax that we can add to a binding environment
            let symbol_cell = SafasCell::Syntax(Box::new(SyntaxSymbol::syntax(symbol.clone())), NIL.clone()).into();

            // Push to the results
            bound_symbols.push((symbol_id, symbol_cell));
            all_symbols.push((symbol_id, symbol));
        }

        // Generate the syntax b-tree (starting at the syntax we're extending, if there is one)
        let mut syntax_btree = extend_syntax.as_ref()
            .and_then(|extend_syntax| match &**extend_syntax { SafasCell::Syntax(_, params) => Some(params.clone()), _ => None })
            .and_then(|params| match btree_search(params, SafasCell::atom("syntax")) { Ok(extended_syntax) => Some(extended_syntax), Err(_err) => None })
            .and_then(|extended_syntax| if extended_syntax.is_btree() { Some(extended_syntax) } else { None })
            .unwrap_or_else(|| btree_new());
        for (symbol_id, value) in bound_symbols.iter() {
            syntax_btree = btree_insert(syntax_btree, (SafasCell::Atom(*symbol_id).into(), value.clone())).expect("Valid BTree");
        }

        // Generate the closure
        SyntaxClosure {
            extend_syntax:      extend_syntax,
            syntax_cells:       bound_symbols, 
            syntax_symbols:     all_symbols, 
            syntax_btree:       syntax_btree,
            imported_bindings:  imported_bindings
        }
    }
///
/// Creates a syntax closure from a list of syntax symbols and imports
///
Creates a syntax closure from a list of syntax symbols and imports
Creates a syntax closure from a list of syntax symbols and imports
pub fn new<SymbolList: IntoIterator<Item=(AtomId, Arc<SyntaxSymbol>)>>(syntax_symbols: SymbolList, imported_bindings: Arc<HashMap<usize, CellRef>>, extend_syntax: Option<CellRef>) -> SyntaxClosure {
        // Add the imported bindings into each syntax symbol to generate the syntax symbols list
        let mut bound_symbols: Vec<(u64, CellRef)>   = vec![];
        let mut all_symbols     = vec![];
        for (AtomId(symbol_id), symbol) in syntax_symbols.into_iter() {
            // Set the imported bindings for the symbol
            let mut symbol  = (*symbol).clone();
            symbol.imported_bindings = Arc::clone(&imported_bindings);
            let symbol      = Arc::new(symbol);
            // Turn into syntax that we can add to a binding environment
            let symbol_cell = SafasCell::Syntax(Box::new(SyntaxSymbol::syntax(symbol.clone())), NIL.clone()).into();
            // Push to the results
            bound_symbols.push((symbol_id, symbol_cell));
            all_symbols.push((symbol_id, symbol));
        }
        // Generate the syntax b-tree (starting at the syntax we're extending, if there is one)
        let mut syntax_btree = extend_syntax.as_ref()
            .and_then(|extend_syntax| match &**extend_syntax { SafasCell::Syntax(_, params) => Some(params.clone()), _ => None })
            .and_then(|params| match btree_search(params, SafasCell::atom("syntax")) { Ok(extended_syntax) => Some(extended_syntax), Err(_err) => None })
            .and_then(|extended_syntax| if extended_syntax.is_btree() { Some(extended_syntax) } else { None })
            .unwrap_or_else(|| btree_new());
        for (symbol_id, value) in bound_symbols.iter() {
            syntax_btree = btree_insert(syntax_btree, (SafasCell::Atom(*symbol_id).into(), value.clone())).expect("Valid BTree");
        }
        // Generate the closure
        SyntaxClosure {
            extend_syntax:      extend_syntax,
            syntax_cells:       bound_symbols, 
            syntax_symbols:     all_symbols, 
            syntax_btree:       syntax_btree,
            imported_bindings:  imported_bindings
        }
    }
pub fn new < SymbolList : IntoIterator < Item = ( AtomId , Arc < SyntaxSymbol > ) > > ( syntax_symbols : SymbolList , imported_bindings : Arc < HashMap < usize , CellRef > > , extend_syntax : Option < CellRef > ) -> SyntaxClosure { // Add the imported bindings into each syntax symbol to generate the syntax symbols list let mut bound_symbols : Vec < ( u64 , CellRef ) > = vec ! [ ] ; let mut all_symbols = vec ! [ ] ; for ( AtomId ( symbol_id ) , symbol ) in syntax_symbols . into_iter ( ) { // Set the imported bindings for the symbol let mut symbol = ( * symbol ) . clone ( ) ; symbol . imported_bindings = Arc :: clone ( & imported_bindings ) ; let symbol = Arc :: new ( symbol ) ; // Turn into syntax that we can add to a binding environment let symbol_cell = SafasCell :: Syntax ( Box :: new ( SyntaxSymbol :: syntax ( symbol . clone ( ) ) ) , NIL . clone ( ) ) . into ( ) ; // Push to the results bound_symbols . push ( ( symbol_id , symbol_cell ) ) ; all_symbols . push ( ( symbol_id , symbol ) ) ; } // Generate the syntax b-tree (starting at the syntax we're extending, if there is one) let mut syntax_btree = extend_syntax . as_ref ( ) . and_then ( | extend_syntax | match & * * extend_syntax { SafasCell :: Syntax ( _ , params ) => Some ( params . clone ( ) ) , _ => None } ) . and_then ( | params | match btree_search ( params , SafasCell :: atom ( " " ) ) { Ok ( extended_syntax ) => Some ( extended_syntax ) , Err ( _err ) => None } ) . and_then ( | extended_syntax | if extended_syntax . is_btree ( ) { Some ( extended_syntax ) } else { None } ) . unwrap_or_else ( | | btree_new ( ) ) ; for ( symbol_id , value ) in bound_symbols . iter ( ) { syntax_btree = btree_insert ( syntax_btree , ( SafasCell :: Atom ( * symbol_id ) . into ( ) , value . clone ( ) ) ) . expect ( " " ) ; } // Generate the closure SyntaxClosure { extend_syntax : extend_syntax , syntax_cells : bound_symbols , syntax_symbols : all_symbols , syntax_btree : syntax_btree , imported_bindings : imported_bindings } }
Creates a syntax closure from a list of syntax symbols and imports
Creates a syntax closure from a list of syntax symbols and imports
syntax_symbols
SymbolList
imported_bindings
Arc<HashMap<usize, CellRef>>
extend_syntax
Option<CellRef>
syntax_symbols
SymbolList
imported_bindings
Arc<HashMap<usize, CellRef>>
extend_syntax
Option<CellRef>