function-exists searches builtin functions and ignores quotes

This commit is contained in:
ConnorSkees 2020-02-14 18:39:50 -05:00
parent c16d6fed4e
commit 7811a3e056

View File

@ -1,6 +1,6 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use super::Builtin; use super::{Builtin, GLOBAL_FUNCTIONS};
use crate::common::QuoteKind; use crate::common::QuoteKind;
use crate::units::Unit; use crate::units::Unit;
use crate::value::Value; use crate::value::Value;
@ -71,7 +71,8 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
}); });
decl!(f "function-exists", |args, scope| { decl!(f "function-exists", |args, scope| {
let value = arg!(args, 0, "name"); let value = arg!(args, 0, "name");
Some(Value::bool(scope.fn_exists(&value.to_string()))) let s = value.eval().unquote().to_string();
Some(Value::bool(scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(&s)))
}); });
decl!(f "call", |_args, _scope| { decl!(f "call", |_args, _scope| {
todo!("builtin function `call()` is blocked on refactoring how call args are stored and parsed") todo!("builtin function `call()` is blocked on refactoring how call args are stored and parsed")