fn with(&self, other: &Program<S>) -> Result<Program<S>, String> {
        if self.alphabet != other.alphabet {
            return Err(format!(
                "extend error: alphabet {:?} and {:?} must be equal",
                &self.alphabet, &other.alphabet
            ));
        }
        let mut program = Program::new(self.alphabet.clone(), self.l_state + other.l_state);
        // `self` and `other` are `Program` instances so it doesn't need to use insert method.
        let extension = self.container.iter().map(|inst| match inst.tail.state {
            State(0) => {
                let mut inst = inst.clone();
                inst.tail.state = self.l_state + State(1);
                inst
            }
            _ => inst.clone(),
        });
        program.container.extend(extension);

        let extension = other.container.iter().map(|inst| {
            let mut inst = inst.clone();
            inst.head.state += self.l_state;
            inst.tail.state += match inst.tail.state {
                State(0) => State(0),
                _ => self.l_state,
            };
            inst
        });
        program.container.extend(extension);

        Ok(program)
    }
/// Returns a new [`Program`] by merging this program with another according to these rules:
/// 1. All [`crate::instruction::Tail`] parts of [`Instruction`]s for this [`Program`]
///     will changes their [`State`]s to `self.l_state` if [`crate::instruction::Tail`]
///     [`State`] equals to `0`.
/// 2. All [`Head`] parts of [`Instruction`]s for another [`Program`] will
///     increase (or shift) their [`State`]s by `self.l_state`.
/// 3. All [`crate::instruction::Tail`] parts of [`Instruction`]s
///     for another program will also increase (or shift) by `self.l_state`
///     but only if [`crate::instruction::Tail`] [`State`] not equals to `0`.
/// 4. A new [`Program`] `l_state` is set to `self.l_state + other.l_state`.
Returns a new [`Program`] by merging this program with another according to these rules:
1.
Returns a new [ ` Program ` ] by merging this program with another according to these rules : 1 .
fn with(&self, other: &Program<S>) -> Result<Program<S>, String> {
        if self.alphabet != other.alphabet {
            return Err(format!(
                "extend error: alphabet {:?} and {:?} must be equal",
                &self.alphabet, &other.alphabet
            ));
        }
        let mut program = Program::new(self.alphabet.clone(), self.l_state + other.l_state);
        // `self` and `other` are `Program` instances so it doesn't need to use insert method.
        let extension = self.container.iter().map(|inst| match inst.tail.state {
            State(0) => {
                let mut inst = inst.clone();
                inst.tail.state = self.l_state + State(1);
                inst
            }
            _ => inst.clone(),
        });
        program.container.extend(extension);
        let extension = other.container.iter().map(|inst| {
            let mut inst = inst.clone();
            inst.head.state += self.l_state;
            inst.tail.state += match inst.tail.state {
                State(0) => State(0),
                _ => self.l_state,
            };
            inst
        });
        program.container.extend(extension);
        Ok(program)
    }
fn with ( & self , other : & Program < S > ) -> Result < Program < S > , String > { if self . alphabet != other . alphabet { return Err ( format ! ( " " self alphabet other alphabet ) ) ; } let mut program = Program :: new ( self . alphabet . clone ( ) , self . l_state + other . l_state ) ; // `self` and `other` are `Program` instances so it doesn't need to use insert method. let extension = self . container . iter ( ) . map ( | inst | match inst . tail . state { State ( 0 ) => { let mut inst = inst . clone ( ) ; inst . tail . state = self . l_state + State ( 1 ) ; inst } _ => inst . clone ( ) , } ) ; program . container . extend ( extension ) ; let extension = other . container . iter ( ) . map ( | inst | { let mut inst = inst . clone ( ) ; inst . head . state += self . l_state ; inst . tail . state += match inst . tail . state { State ( 0 ) => State ( 0 ) , _ => self . l_state , } ; inst } ) ; program . container . extend ( extension ) ; Ok ( program ) }
Returns a new [`Program`] by merging this program with another according to these rules:
1.
Returns a new [ ` Program ` ] by merging this program with another according to these rules : 1 .
&self
other
&Program<S>
&self
other
&Program<S>