diff --git a/assets/prelude.ld b/assets/prelude.ld index 7d2646b..6c9ed8e 100644 --- a/assets/prelude.ld +++ b/assets/prelude.ld @@ -295,7 +295,13 @@ fn concat { fn contains? { "Returns true if a set or list contains a value." & (value, s as :set) -> bool (base :get (s, value)) - (value, l as :list) -> contains? (value, set (list)) + (value, l as :list) -> loop (l) with { + ([]) -> false + ([x]) -> eq? (x, value) + ([x, ...xs]) -> if eq? (x, value) + then true + else recur (xs) + } } & fn omit { diff --git a/assets/test_prelude.ld b/assets/test_prelude.ld index 6734057..195b361 100644 --- a/assets/test_prelude.ld +++ b/assets/test_prelude.ld @@ -10,6 +10,8 @@ fn dec (n as :number) -> base :sub (n, 1) fn sub (x as :number, y as :number) -> base :sub (x, y) +fn panics! () -> add ("foo", "bar") + fn print!(x) -> base :print! (x) -#{add, dec, sub, print!} +#{add, dec, sub, print!, panics!} diff --git a/src/base.rs b/src/base.rs index edee9a7..3c4d8ce 100644 --- a/src/base.rs +++ b/src/base.rs @@ -257,7 +257,9 @@ pub fn or<'src>(x: &Value<'src>, y: &Value<'src>) -> Value<'src> { Value::Boolean(x.bool() || y.bool()) } +// TODO: fix this: x is a list of all the args passed to Ludus's print! pub fn print<'src>(x: &Value<'src>) -> Value<'src> { + // dbg!(x) println!("{}", x); Value::Keyword("ok") } diff --git a/src/main.rs b/src/main.rs index adbe1a8..ca9c620 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ // * [x] investigate using labels (which is behind a compiler flag, somehow) // * [ ] write parsing errors // * [ ] wire up Ariadne parsing errors -// * [ ] add stack traces and code locations to panics +// * [x] add stack traces and code locations to panics // * [x] validation // * [x] break this out into multiple files // * [x] write a tree-walk VM @@ -70,7 +70,7 @@ pub fn prelude<'src>() -> ( Vec<(String, Value<'src>)>, std::collections::HashMap<*const Ast, FnInfo>, ) { - let prelude = Asset::get("test_prelude.ld").unwrap().data.into_owned(); + let prelude = Asset::get("prelude.ld").unwrap().data.into_owned(); // we know for sure Prelude should live through the whole run of the program let leaked = Box::leak(Box::new(prelude)); let prelude = std::str::from_utf8(leaked).unwrap(); diff --git a/src/validator.rs b/src/validator.rs index 6fad284..4ff9ade 100644 --- a/src/validator.rs +++ b/src/validator.rs @@ -536,7 +536,7 @@ impl<'a, 'src: 'a> Validator<'a, 'src> { unreachable!() }; - dbg!(&input); + // dbg!(&input); let tailpos = self.status.tail_position; self.status.tail_position = true; @@ -551,7 +551,7 @@ impl<'a, 'src: 'a> Validator<'a, 'src> { self.ast = expr; self.span = *span; let arity = self.arity(); - dbg!(&arity); + // dbg!(&arity); match arity { Arity::Fixed(clause_arity) => { if clause_arity != loop_arity { @@ -644,7 +644,7 @@ impl<'a, 'src: 'a> Validator<'a, 'src> { }, _ => { println!("internal Ludus error: unexpected splat pattern"); - dbg!(splatted); + // dbg!(splatted); unreachable!() } }