Struct LazyKProgram

Source
pub struct LazyKProgram { /* private fields */ }

Implementations§

Source§

impl LazyKProgram

Compiled LazyK program, ready to be executed.

Source

pub fn compile(source: &str) -> Result<Self>

Compiles LazyK source to a runnable program.

use lazyk_rust::LazyKProgram;
let source = "I";
let mut program = LazyKProgram::compile(source).unwrap();
assert_eq!(program.run_string("abcd").unwrap(), "abcd");
Source

pub fn set_output_limit(&mut self, value: Option<usize>)

Sets maximal number of cbytes in output, after which program halts. Useful for running programs that produce infinite ouput.

Source

pub fn run_vec(&mut self, input: Vec<u8>) -> Result<Vec<u8>>

Runs program as Vec -> Vec function.

Source

pub fn run_string(&mut self, input: &str) -> Result<String>

Runs program as String -> String function.

Source

pub fn run_console(&mut self) -> Result<()>

Runs program, reading from standard input and writing to standard output.

Source

pub fn to_source(&self, style: Style) -> String

Produces source code for this program.

There are four supported styles: combinator-calculus, Unlambda, Jot and Iota.

use lazyk_rust::{LazyKProgram, Style};
let prog = LazyKProgram::compile("S(SI(K(KI)))(K(KI))").unwrap();
assert_eq!(prog.to_source(Style::CombCalculus), "S(SI(K(KI)))(K(KI))");
assert_eq!(prog.to_source(Style::Unlambda), "``s``si`k`ki`k`ki");                                         
assert_eq!(prog.to_source(Style::Jot), "11111110001111111000111111111000001111001111001111111110000011110011110011111111100000");
assert_eq!(prog.to_source(Style::Iota), "***i*i*i*ii***i*i*i*ii*ii**i*i*ii**i*i*ii*ii**i*i*ii**i*i*ii*ii");
Source

pub fn make_printer(bytes: &[u8]) -> LazyKProgram

Produces LazyK program that prints given byte sequence to output.

use lazyk_rust::LazyKProgram;
let mut prog = LazyKProgram::make_printer("Hi!".as_bytes());
assert_eq!(prog.run_string("").unwrap(), "Hi!");

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.