Arc Forumnew | comments | leaders | submitlogin
Listtab
3 points by cacplate 3697 days ago | 4 comments
Why is there listtab if we can do the same thing with obj which is less verbose and more pretty from my point of view?


2 points by zck 3697 days ago | link

If nothing else, you can use 'listtab to convert an association list (http://arclanguage.github.io/ref/assoc.html) to a table:

    arc> (= al '((k1 v1) (k2 v2)))
    ((k1 v1) (k2 v2))
    arc> (alref al 'k2)
    v2
    arc> (listtab al)
    #hash((k1 . v1) (k2 . v2))
And it is more readable for long argument lists:

    arc> (obj 1 2 3 4 5 6 7 8 9 0 a 2 b 3 r 4) ;; Is 0 a key or a value?
    #hash((r . 4) (1 . 2) (b . 3) (3 . 4) (a . 2) (5 . 6) (7 . 8) (9 . 0))
    arc> (listtab '((1 2) (3 4) (5 6) (7 8) (9 0) (a 2) (b 3) (r 4))) ;; a val.
    #hash((r . 4) (1 . 2) (b . 3) (3 . 4) (a . 2) (5 . 6) (7 . 8) (9 . 0))

-----

2 points by akkartik 3697 days ago | link

In addition to zck's points: obj is built using listtab, and there's several cases in arc where 'internal' helpers are not distinguished from the external interface. That gives users the option to use it in the rare situations where it's more helpful.

-----

2 points by cacplate 3697 days ago | link

Those are pretty good points thanks.

-----

3 points by zck 3697 days ago | link

Glad to help out!

Also, it looks like you're new here. Welcome! Feel free to post any questions or thoughts about Arc; this forum is really welcoming to newcomers, and I'd like the community to grow bigger.

-----