From 8535225167751ef22c6a734e2d87ba879be4bbee Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Fri, 13 Dec 2024 13:47:03 -0500 Subject: [PATCH] fix print! --- assets/prelude.ld | 10 ++++++---- src/base.rs | 11 +++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/assets/prelude.ld b/assets/prelude.ld index 6c9ed8e..b6daf0c 100644 --- a/assets/prelude.ld +++ b/assets/prelude.ld @@ -227,9 +227,10 @@ fn fold { } } -& TODO: optimize these with base :conj! fn map { - "Maps a function over a list: returns a new list with elements that are the result of applying the function to each element in the original list. E.g., `map ([1, 2, 3], inc) &=> [2, 3, 4]`." + "Maps a function over a list: returns a new list with elements that are the result of applying the function to each element in the original list. E.g., `map ([1, 2, 3], inc) &=> [2, 3, 4]`. With one argument, returns a function that is a mapper over lists; with two, it executes the mapping function right away." + (f as :fn) -> map (f, _) + (kw as :keyword) -> map (kw, _) (f as :fn, xs) -> { fn mapper (prev, curr) -> append (prev, f (curr)) fold (mapper, xs, []) @@ -242,6 +243,7 @@ fn map { fn filter { "Takes a list and a predicate function, and returns a new list with only the items that produce truthy values when the function is called on them. E.g., `filter ([1, 2, 3, 4], odd?) &=> [1, 3]`." + (p? as :fn) -> filter (p?, _) (p? as :fn, xs) -> { fn filterer (filtered, x) -> if p? (x) then append (filtered, x) @@ -256,7 +258,7 @@ fn keep { } fn append { - "Adds an element to a list or set." + "Adds an element to a list." () -> [] (xs as :list) -> xs (xs as :list, x) -> base :conj (xs, x) @@ -273,7 +275,7 @@ fn append! { fn concat { "Combines two lists, strings, or sets." - (x as :string, y as :string) -> base :concat (x, y) + (x as :string, y as :string) -> "{x}{y}" (xs as :list, ys as :list) -> base :concat (xs, ys) & (xs as :set, ys as :set) -> base :concat (xs, ys) (xs, ys, ...zs) -> fold (concat, zs, concat (xs, ys)) diff --git a/src/base.rs b/src/base.rs index 3c4d8ce..1a40e5c 100644 --- a/src/base.rs +++ b/src/base.rs @@ -259,8 +259,15 @@ pub fn or<'src>(x: &Value<'src>, y: &Value<'src>) -> Value<'src> { // 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); + let Value::List(args) = x else { + unreachable!("internal Ludus error") + }; + let out = args + .iter() + .map(|val| format!("{val}")) + .collect::>() + .join(""); + println!("{out}"); Value::Keyword("ok") }