egallesio / STklos

STklos Scheme
http://stklos.net
GNU General Public License v2.0
69 stars 17 forks source link

Use `~W` for general objects, not `~S` #608

Closed jpellegrini closed 5 months ago

jpellegrini commented 1 year ago

Hi @egallesio !

Error messages do not know what the object is, so they shouldn't assume it's not circular:

(define c (list 1 2 3 4))
(set-cdr! (cdddr c) (cdr c))
(+ c)
  => loops
jpellegrini commented 1 year ago

Maybe this also happens in other files. I just checked number.c...

jpellegrini commented 1 year ago

I have added patches for other files (not all of them)...

But I wonder if it wouldn't make sense to have a single directive, ~S, that would already deal properly with circular structures?

egallesio commented 5 months ago

You are right @jpellegrini,

I should have seen this.

But I wonder if it wouldn't make sense to have a single directive, ~S, that would already deal properly with circular structures?

That would be probably a better solution. We could make ~S and ~W be equivalent in error messages. For errors, the format parsing is done in the specific function print_format in file src/error.c. This should be easier than passing on all files (and when we have an error, the overhead implied by ~W doesn't matter).

egallesio commented 5 months ago

Hi @jpellegrini, I have modified the formatting function for errors. Now, both ~S and ~W use write* to print the culprit in an error message. Thanks for signaling the problem. Since, it should resolve the problem, I close this PR, but you can reopen it, if needed.

jpellegrini commented 5 months ago

Great news! :smile: