torch / tds

Torch C data structures
Other
80 stars 25 forks source link

hash / vec: add support for boolean type #9

Closed deltheil closed 8 years ago

deltheil commented 8 years ago

This makes it closer to what can be done with plain Lua tables (it is also interesting to convert JSON -> tds, even though the special case of JSON null is not covered out-of-the-box).

Prior to this PR, true was clearly stated as unsupported, but false had side effects (it removed the entry for a hash, and was stored as a nil element for a vec).

Last: I made the choice to write tests like if lval or type(lval) == 'boolean' then instead of if type(lval) ~= 'nil' then (more readable) to take benefit of short-circuit evaluations, i.e. type() is called only for nil and false values.

soumith commented 8 years ago

Looks good, and a pretty nice PR.

andresy commented 8 years ago

:+1: