pub enum SExp {
    Null,
    Atom(Primitive),
    Pair {
        head: Box<SExp>,
        tail: Box<SExp>,
    },
}
Expand description

An S-Expression. Can be parsed from a string via FromStr, or constructed programmatically.

Examples

use parsley::SExp;
let null = "()".parse::<SExp>().unwrap();
assert_eq!(null, SExp::Null);
use parsley::SExp;
let parsed = "\"abcdefg\"".parse::<SExp>().unwrap();
assert_eq!(parsed, SExp::from("abcdefg"));

Variants

Null

Atom(Primitive)

Pair

Fields

head: Box<SExp>
tail: Box<SExp>

Implementations

Iterate over an S-Expression, by reference.

Example
use parsley::prelude::*;
assert_eq!(
    sexp![()].iter().next().unwrap(),
    &SExp::Null
);

Easy way to check for Null if you’re planning on iterating

Get the length of an S-Expression (vector or list)

Example
use parsley::prelude::*;
assert_eq!(
    sexp!['a', "bee", SExp::sym("sea")].len(),
    3
);

The natural way to build up a list - from the end to the beginning.

Example
use parsley::prelude::*;
use parsley::SExp::Null;

let macro_list = sexp![SExp::sym("quote"), ()];
let cons_list = Null.cons(Null).cons(SExp::sym("quote"));

assert_eq!(macro_list, cons_list);

Convenience method to build a symbolic atom.

Example
use parsley::prelude::*;
let mut ctx = Context::base();

// A null list is an empty application
assert!(ctx.eval(SExp::Null).is_err());

// The symbol `null` (defined in `Context::base`) creates a null when evaluated
let result = ctx.run("null").unwrap();
assert_eq!(result, SExp::Null);

Printable type for an expression.

Example
use parsley::SExp;

assert_eq!(SExp::Null.type_of(), "null");
assert_eq!(SExp::from(3).type_of(), "number");
assert_eq!(SExp::from(true).type_of(), "bool");
assert_eq!(SExp::from((5,)).type_of(), "list");

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Creates a value from an iterator. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.