robpike / ivy

ivy, an APL-like calculator
Other
1.33k stars 103 forks source link

a way to construct multidimensional array without rho? #117

Closed smasher164 closed 1 year ago

smasher164 commented 1 year ago

Is there a way to construct a multidimensional array with regular data entry? In Dyalog, you can just write

> (1 2 3)(4 5)
┌─────┬───┐
│1 2 3│4 5│
└─────┴───┘

Thanks

robpike commented 1 year ago

No, there is not. It was a deliberate decision for simplicity. It could be changed but would be a fair bit of work.

smasher164 commented 1 year ago

I see. Is there a recommendation or hack for constructing such arrays if such syntax doesn't exist? I was trying to do simple processing over an array like

[1000 2000 3000]

[4000]

[5000 6000]

[7000 8000 9000]

yesterday for Advent of Code, but gave up since I couldn't get the input into ivy.

robpike commented 1 year ago

The engine doesn't support them, so there is no way to inject them.

mykhal commented 1 year ago

Sometimes, vectors inside vector is obtained, looking flat at first sight:

x = ,\iota 3

x
result: 1 1 2 1 2 3

rho x
result: 3

x[1]
result: 1

x[2]
result: 1 2

x[3]
result: 1 2 3

.. So if these cannot be constructed literally, shouldn't the result be flat and/or "Everything in ivy can be placed into a vector" statement from the demo be corrected?

UPDATE: the same result here considered an error

robpike commented 1 year ago

As you can see from the commit above, you got what you wanted.

I suspect there remain rough edges. I know that printing still needs work, but have a handle on that. I'll leave this issue open at least until that is resolved.

Thanks for the prod.