Lines
100 %
Functions
Branches
//! 0014 Stage 3.1b (ISS-125): LIST and CONS keep a quoted member's datum, not
//! the evaluation wrapper of the quote that produced it.
use crate::ast::Expr;
use crate::compiler::expr::eval_value;
use crate::reader::Reader;
use crate::runtime::SymbolTable;
fn form(source: &str) -> Expr {
Reader::parse(source)
.ok()
.and_then(|program| program.exprs.into_iter().next())
.unwrap_or(Expr::Nil)
}
fn eval(source: &str) -> Expr {
let mut symbols = SymbolTable::with_builtins_for_wasm();
eval_value(&mut symbols, &form(source)).unwrap_or(Expr::Nil)
#[test]
fn list_members_are_data_symbols() {
assert_eq!(eval("(list 'a 'b)"), eval("'(a b)"));
fn list_keeps_a_member_list_as_data() {
assert_eq!(eval("(list 'let '((b 1)) 'b)"), eval("'(let ((b 1)) b)"));
fn list_keeps_a_quote_that_is_part_of_the_datum() {
assert_eq!(eval("(list ''a)"), eval("'('a)"));
fn cons_car_is_a_data_symbol() {
assert_eq!(eval("(cons 'quote (list 'b))"), eval("'(quote b)"));
fn cons_onto_a_constant_list_keeps_a_data_member() {
assert_eq!(eval("(cons 'a '(b))"), eval("'(a b)"));
fn append_of_lists_with_data_symbols_is_data() {
assert_eq!(
eval("(append (list 'return-from 'b) (list 9))"),
eval("'(return-from b 9)")
);