For debugging, I often display the value of a variable (or values of multiple variables) in a user message.
This has considerable advantages compared to print or show.
Now with user-message [“1” “2” “3”] (reduced from a more complex example),
to my surprise the message shows [1 2 3] rather than [”1” “2” “3”]that I expected.
The behavior is reproducible for any strings in a list, even nested lists.
This is at least very confusing.
But I could not find this behavior anywhere in the user manual or dictionary, either.
So, I consider this a bug.
If it was intended, is there an alternative for getting the representation including quotes?
I tried variants using word, but that works exactly as above.
(show does include the quotes, but writes the answer to the command center)
In the common use case, the user provides a string to primitves like user-message and word, so I don’t think it would be a good idea to automatically wrap strings in quotes for those primitives. For example, you wouldn’t want word “one” “two” to output "one””two”, or for user-message “Hello, World!” to display those quotes in the dialog box. If your use case turns out to be more common, we could consider adding a primitive to provide your desired functionality, but there’s a pretty simple workaround you can use for now:
You can use this on bare objects, or map it to a list with map wrap-string [ “1” “2” “3” ]. The sample code I provided can also be expanded to work with deeper levels of nesting, so let me know if you need that functionality as well and have trouble implementing it.
Fair enough!
If this intended, I can make a work-around for the debugging/user-message use case.
At the moment I can’t find a more convincing use case.
However, the examples without lists are not what surprised me. I fully agree that you wouldn’t want quotes displayed.
The distinction between a list of numbers and a list of strings might be significant, though.
Most other languages either require to do the conversion yourself in all cases, or they do make the difference when supporting automatic conversion.
I was thinking about Python’s str (and repr) function.
For the use case described here, I have created an include file that can be used for getting the user messsages. For debugging, including a file temporarily is not too much overhead.
I’ll post my include file in category “Share & Showcase”.
It’s not clear to me why we would want the quotes removed. The fact that ["1"] = read-from-string (word ["1"]) is false seems wrong to me. And the behavior of:
> show (word ["apples and oranges" "and bananas"])
observer: "[apples and oranges and bananas]"
I agree with you that the behavior in these cases is undesirable, but it also seems wrong to me to quote some strings and not others in the case of user-message or word. I feel like we should have consistency within each primitive, and if we can’t achieve that consistency, we should make a new primitive to achieve the desired behavior.
Thank you @Jason for providing read-from-string as a more convincing use case.
I am looking forward to a solution, either changing the behavior of word, or introducing a new primitive.
For the first choice, I would expect that would then also apply to all cases where non-strings are converted to strings internally.
For the second choice, may I suggest the name repr?