Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ivy: unexpected indentation in matrix of vectors #193

Closed
rsc opened this issue Dec 27, 2024 · 4 comments
Closed

ivy: unexpected indentation in matrix of vectors #193

rsc opened this issue Dec 27, 2024 · 4 comments

Comments

@rsc
Copy link
Contributor

rsc commented Dec 27, 2024

mix (1 2 3) (4 5 6)
1 2 3
4 5 6

mix ('abc' ('d' 'efg')) ('hij' ('k' 'lmn'))
    (abc) (d (efg))
    (hij) (k (lmn))

mix ('abc' ('d' ('efg' 'EFG'))) ('hij' ('k' ('lmn' 'LMN')))
            (abc) (d ((efg) (EFG)))
            (hij) (k ((lmn) (LMN)))

I'm not sure what the leading indentation is, but note how it increases with the vector nesting depth.

@rsc
Copy link
Contributor Author

rsc commented Dec 27, 2024

Oh, I see. It is making all columns the same width and right-aligning the data.
I wonder whether right-alignment should be reserved for numbers or even integers.

I'm also unsure about making all columns the same width when the widths are very different.
I'm playing with matrices as dictionaries, with each row a key-value pair, and they typically have short keys and long values, but the key column ends up with many many spaces at the front.

@robpike
Copy link
Owner

robpike commented Dec 27, 2024

There is a lot of judgement involved here. I tried to make the output generally readable, but with large elements of course that's very hard. It's had several iterations.

For simple things the alignment is how I remember APL\360 working, but of course that was half a century ago. (Really.) My memory may be faulty, or things may have changed, or other changing things may argue for other tradeoffs. The trick is doing the right thing most of the time, perhaps at the cost of some ugliness in oddball cases.

@rsc
Copy link
Contributor Author

rsc commented Dec 28, 2024

Another example to consider in any future tweak of the heuristics. Playing with the game of life from #194, displaying a matrix of boxed matrices could possibly use blank lines between rows of the outer matrix.

R = -1 flip -2 rot 5 7 take (3 3 rho iota 9) in 2 3 4 5 8

1 0 -1 @rot R
(0 0 0 0 0 0 0| (0 0 0 0 0 0 0| (0 0 0 0 0 0 0|
|0 0 1 1 0 0 0| |0 0 0 1 1 0 0| |0 0 0 0 1 1 0|
|0 1 1 0 0 0 0| |0 0 1 1 0 0 0| |0 0 0 1 1 0 0|
|0 0 1 0 0 0 0| |0 0 0 1 0 0 0| |0 0 0 0 1 0 0|
|0 0 0 0 0 0 0) |0 0 0 0 0 0 0) |0 0 0 0 0 0 0)

1 0 -1 o.flip 1 0 -1 @rot R
(0 0 1 1 0 0 0| (0 0 0 1 1 0 0| (0 0 0 0 1 1 0|
|0 1 1 0 0 0 0| |0 0 1 1 0 0 0| |0 0 0 1 1 0 0|
|0 0 1 0 0 0 0| |0 0 0 1 0 0 0| |0 0 0 0 1 0 0|
|0 0 0 0 0 0 0| |0 0 0 0 0 0 0| |0 0 0 0 0 0 0|
|0 0 0 0 0 0 0) |0 0 0 0 0 0 0) |0 0 0 0 0 0 0)
(0 0 0 0 0 0 0| (0 0 0 0 0 0 0| (0 0 0 0 0 0 0|
|0 0 1 1 0 0 0| |0 0 0 1 1 0 0| |0 0 0 0 1 1 0|
|0 1 1 0 0 0 0| |0 0 1 1 0 0 0| |0 0 0 1 1 0 0|
|0 0 1 0 0 0 0| |0 0 0 1 0 0 0| |0 0 0 0 1 0 0|
|0 0 0 0 0 0 0) |0 0 0 0 0 0 0) |0 0 0 0 0 0 0)
(0 0 0 0 0 0 0| (0 0 0 0 0 0 0| (0 0 0 0 0 0 0|
|0 0 0 0 0 0 0| |0 0 0 0 0 0 0| |0 0 0 0 0 0 0|
|0 0 1 1 0 0 0| |0 0 0 1 1 0 0| |0 0 0 0 1 1 0|
|0 1 1 0 0 0 0| |0 0 1 1 0 0 0| |0 0 0 1 1 0 0|
|0 0 1 0 0 0 0) |0 0 0 1 0 0 0) |0 0 0 0 1 0 0)

@robpike robpike closed this as completed in 41bfcf2 Jan 8, 2025
@robpike
Copy link
Owner

robpike commented Jan 8, 2025

Reopening because the fix only addresses the last comment.

@robpike robpike reopened this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants