Arc Forumnew | comments | leaders | submitlogin
Writing a sane list macro
2 points by hjek 2244 days ago | 2 comments
I'm trying to write a macro for producing HTML lists, and I'm not sure if I'm doing it right.

This macro should be given some expressions that print HTML and turn them into a HTML list, for example

    (ol (link "foo") (link "bar"))
should return something like

    <ol>
    <li><a href="foo">foo</a></li>
    <li><a href="bar">bar</a></li>
    </ol>  
I wrote a macro that does give that result,

    (mac ol items
      `(tag ol
            (map [tag li (pr _)]
                 (map tostring:eval '(,@items)))))
but my first thought is that it might be hacky and unnecessary to use `eval` for this, and perhaps even a potential security issue like when people use `eval` in JavaScript.

Any thoughts on this?



2 points by hjek 2244 days ago | link

Never mind, found less hacky solution:

    (mac li item
      `(tag li ,@item))

    (mac ol items
      `(tag ol ,@(map [list 'li _] items)))

-----

2 points by akkartik 2244 days ago | link

That seems pretty much unhacky :)

-----