Skip to content

Commit

Permalink
fix: (str nil) => "" (#264)
Browse files Browse the repository at this point in the history
* fix: (str nil) => empty string

* cleanup

* remove condition; cleanup

* format

* move code out of visit_seqable lambda

* pass 'buff' to visit_seqable lambda

* specify arg type
  • Loading branch information
bpiel authored Feb 20, 2025
1 parent 7b69a4e commit 2ab796a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 15 additions & 11 deletions compiler+runtime/src/cpp/jank/runtime/core/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,23 +930,27 @@ namespace jank::runtime

native_persistent_string str(object_ptr const o, object_ptr const args)
{
util::string_builder buff;
buff.reserve(16);
if(!is_nil(o))
{
runtime::to_string(o, buff);
}
return visit_seqable(
[=](auto const typed_args) -> native_persistent_string {
util::string_builder buff;
buff.reserve(16);
runtime::to_string(o, buff);
if(0 < sequence_length(typed_args))
{
auto const fresh(typed_args->fresh_seq());
runtime::to_string(fresh->first(), buff);
for(auto it(fresh->next_in_place()); it != nullptr; it = it->next_in_place())
[](auto const typed_args, util::string_builder &buff) -> native_persistent_string {
for(auto it(typed_args->fresh_seq()); it != nullptr; it = it->next_in_place())
{
auto const fst(it->first());
if(is_nil(fst))
{
runtime::to_string(it->first(), buff);
continue;
}
runtime::to_string(fst, buff);
}
return buff.release();
},
args);
args,
buff);
}

obj::persistent_list_ptr list(object_ptr const s)
Expand Down
4 changes: 3 additions & 1 deletion compiler+runtime/src/jank/clojure/core.jank
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@
([]
"")
([o]
(clojure.core-native/to-string o))
(if (nil? o)
""
(clojure.core-native/to-string o)))
([o & args]
(clojure.core-native/str o args))))

Expand Down

0 comments on commit 2ab796a

Please sign in to comment.