Arc Forumnew | comments | leaders | submitlogin
Auto printing strings in tags
9 points by aw 3563 days ago | 1 comment
A lot of my paragraph tags look like

  (tag p (pr "blah blah blah"))
which I can shorten with a procedure p like Arc's para:

  (def p args
    (tag p (apply pr args)))

  (p "blah blah blah")
On occasion though I need to include some tags in my paragraph, so I'm back to having to use pr:

  (tag p
    (pr "blah blah ")
    (tag b (pr "blah"))
    (pr " blah"))
I noticed that within a tag, a plain string doesn't do anything (the value is just thrown away), and so it wouldn't hurt to have plain strings automatically printed.

With a macro helper function,

  (def autopr (args)
    (map [if (isa _ 'string) `(pr ,_) _] args))

  (mac p args
    `(tag p
       ,@(autopr args)))

  (mac b args
    `(tag b
       ,@(autopr args)))

  arc> (p "blah blah " (b "blah") " blah")
  <p>blah blah <b>blah</b> blah</p>


2 points by aw 3562 days ago | link

Though I ran into trouble naming my macro with such a short name as "p", as it turned out I also had written a function that took "p" as an argument...

  arc> (def foo (p)
         (= p!a 'bar))
  Warning: Inverting what looks like a function call. (p (quote a)) ((fn () (pr "<p>") (quote a) (pr "</p>"))) 
  #<procedure: foo>

-----