[−][src]Macro lexpr::sexp
Construct a Value
using syntax similar to regular S-expressions.
The macro is intended to have a feeling similiar to an implicitly quasiquoted Scheme expression.
Booleans
let t = sexp!(#f); let f = sexp!(#t);
Symbols and keywords
Due to syntactic restrictions of Rust's macro system, to use
kebab-case, you need to use the #"..."
syntax.
let sym = sexp!(symbol); let kw = sexp!(#:keyword); assert!(sym.is_symbol()); assert!(kw.is_keyword()); let kebab_sym = sexp!(#"kebab-symbol"); let kebab_kw = sexp!(#:"kebab-keyword"); assert!(kebab_sym.is_symbol()); assert!(kebab_kw.is_keyword());
Characters
Characters can be written using Rust's character syntax:
let ch = sexp!('λ'); assert!(ch.is_char()); assert_eq!(ch.as_char(), Some('λ'));
Lists
Lists can be formed by using the same syntax as in Lisp, including dot notation.
let l1 = sexp!((1 2 3)); let l2 = sexp!((1 . (2 . (3 . ())))); let l3 = sexp!((1 2 . (3 . ()))); assert_eq!(l1, l2); assert_eq!(l2, l3);
Improper (aka dotted) lists are supported as well:
let dotted = sexp!((1 2 . three)); assert!(dotted.is_dotted_list()); let tail = dotted.as_cons().unwrap().cdr(); assert!(tail.is_cons()); assert_eq!(tail, &sexp!((2 . three)));
Vectors
Vectors can be written using Scheme notation, e.g.:
let v = sexp!(#(1 2 "three")); assert!(v.is_vector()); assert_eq!(v[2], sexp!("three"));