Add test file, implement and/or/not, prepare for proper compound proc
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::interpreter::has_tag;
|
||||
use crate::interpreter::is_true;
|
||||
use crate::parser::make_symbol;
|
||||
use crate::parser::Datum;
|
||||
use crate::parser::Datum::*;
|
||||
@@ -89,6 +90,44 @@ pub fn lt(args: Vec<Datum>) -> Datum {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn or(args: Vec<Datum>) -> Datum {
|
||||
if args.len() == 1 {
|
||||
Boolean(false)
|
||||
} else {
|
||||
for i in 1..args.len() {
|
||||
if is_true(&args[i]) {
|
||||
return args[i].clone();
|
||||
}
|
||||
}
|
||||
Boolean(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn and(args: Vec<Datum>) -> Datum {
|
||||
if args.len() == 1 {
|
||||
Boolean(true)
|
||||
} else {
|
||||
for i in 1..args.len() {
|
||||
if !is_true(&args[i]) {
|
||||
return Boolean(false);
|
||||
}
|
||||
}
|
||||
args[args.len() - 1].clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn not(args: Vec<Datum>) -> Datum {
|
||||
if args.len() != 2 {
|
||||
panic!("NOT -- takes one argument");
|
||||
} else {
|
||||
if is_true(&args[1]) {
|
||||
Boolean(false)
|
||||
} else {
|
||||
Boolean(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display(args: Vec<Datum>) -> Datum {
|
||||
for i in 1..args.len() {
|
||||
print!("{}", args[i]);
|
||||
|
||||
Reference in New Issue
Block a user