table (value-at) inconsistent #113

Closed
paulrd opened this Issue Dec 19, 2012 · 5 comments

Comments

Projects
None yet
2 participants
Contributor

paulrd commented Dec 19, 2012

Using 1.4.2 I try to use (value-at tbl 0) and this returns a map with keys such that they are the keys that would be used by the (table-model :key ). However, after an error occurs (index out of bounds on the table), it returns the key value as given by :text .

The funny thing is that if I get the the TableModel and use .getColumnName it gives me the text value.

Not sure how to control this behavior. Not sure why it depends on there having been an error generated at some point.

Owner

daveray commented Dec 19, 2012

Could you provide a repl session or example that reproduces what you're seeing?

Contributor

paulrd commented Dec 19, 2012

(use '[seesaw core table])
(def tbl
(table :model [:columns [{:key :a :text "a"} {:key :b :text "b"}]
:rows [[:a "bee" :b "cee"]
[:a "tree" :b "four"]]]))
(value-at tbl 0) ; {:b "bee", :a :a}
(value-at tbl 9) ; ArrayIndexOutOfBoundsException 9 >= 2 java.util.Vector.elementAt (Vector.java:470)
(value-at tbl 0) ; {"a" :a, "b" "bee"}

Contributor

paulrd commented Dec 19, 2012

My current workaround is to put:
(try (value-at tbl -1)
(catch Throwable t
nil))
before the 'real' (value-at tbl inx) if I want text keys

But then it would be better to call it value-at!.

Owner

daveray commented Dec 19, 2012

Ok. Two things. First, the exception behavior your seeing is a bug, now fixed. Obviously, value-at should always return the same thing given the same args if the table isn't modified. That will be in the next release. Until then, I'd recommend guarding with (row-count tbl) if it's likely you'll be passing bad indexes. The exception manages to blow out the proxy impl of the table which is where the inconsistent behavior comes from.

Second, your rows should be maps, [{:a "bee" :b "cee"} {:a "tree" :b "four"}], not vectors.

Contributor

paulrd commented Dec 19, 2012

That should do it. That bit where I used a vector was a typo. I'm going to use (.getColumnName (.getModel ...) ...) to access the column name text.

@paulrd paulrd closed this Dec 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment