moonbitlang / core

MoonBit's Core library
https://moonbitlang.com/
Apache License 2.0
533 stars 61 forks source link

ambiguous debug output for `List` #687

Closed skylee03 closed 3 weeks ago

skylee03 commented 1 month ago

The current dubug output cannot accurately display the nested structure of lists.

For example:

fn main {
  let ls = @immut/list.of([
    @immut/list.of([1, 2, 3]),
    @immut/list.of([4, 5, 6]),
    @immut/list.of([7, 8, 9]),
  ])
  debug(ls) // 1, 2, 3, 4, 5, 6, 7, 8, 9
  println(ls) // List::[List::[1, 2, 3], List::[4, 5, 6], List::[7, 8, 9]]
}

It is better to change the output of debug_write to a format similar to the one of to_string.


Related PRs:

Yoorkin commented 1 month ago

The result of List::debug_write should be [1,2,3,...,N]

skylee03 commented 1 month ago

The result of List::debug_write should be [1,2,3,...,N]

I'll try to update it, then I can update #688 accordingly.

skylee03 commented 1 month ago

I noticed that for other data structures, such as Queue, we used the result of to_string as the result of debug_write. Should we do the same for List to ensure consistency?

fn main {
  let q = @queue.of([1, 2, 3])
  println(q) // Queue::[1, 2, 3]
  debug(q) // Queue::[1, 2, 3]
}
qazxcdswe123 commented 1 month ago

Should the debug_write also show the type?

The result of List::debug_write should be [1,2,3,...,N]

or List::[1,2,3,...,N]

@Yoorkin

Yoorkin commented 1 month ago

Should the debug_write also show the type?

There will be some changes to the built-in Debug and Show traits, so we could fix these behaviors later.

skylee03 commented 3 weeks ago

The Debug trait has been removed and the output of println looks fine. Therefore, this issue can be considered fixed.