Arc Forumnew | comments | leaders | submitlogin
Comments on html.arc
11 points by kens2 6059 days ago | 12 comments
I've been looking at html.arc and have a few comments.

One interesting thing is most of the functions are stdout-based. That is, they print output to stdout and they include body code that outputs to stdout. The return values are just noise, and ignored.

However, a few operations (prbold, para) inexplicably use the value of their arguments, rather than being stdout-based. So you'd do (underline (pr "hello")) but (prbold "hello"). (And why the inconsistent name for prbold?) And then a few things like td support either atoms or stdout. So there are three different models for wrapping tags around content.

The inputs macro is a bit bizarre; if the label for an input is the symbol password, then the input uses the password input type, otherwise the input is a regular text input. Tying the input type to its text label in this way is just wrong.

The implementation is very interesting; it uses a bunch of functions opstring, opnum, opsym, etc that generate code. The tag macro is then basically a wrapper around the appropriate function, to turn it into a macro. It looks to me like this is a way of getting the benefits of first-class macros without first-class macros; since the code-generating functions are just functions, they can be put in tables and passed around, and then the macro wrapper makes them work like macros.

If you try to use a tag attribute that Arc doesn't know about, it puts a comment in the HTML <!-- ignoring mytag for a-->. Error reporting in the HTML itself seems like a bad idea.

Hardwiring the spacer gif to s.gif seems like a bad thing. You could redefine (blank-gif), but that seems ugly. Overall, there are a number of strange hardwired thing, e.g. whitepage defines the link color and sptab defines a cellspacing of 7.

underlink: creates a link with <u> underlining around the text. I'm not a CSS zealot, but really.

There are three escape functions: pr-escaped, esc<>&, and eschtml. They all escape slightly different characters. Two return strings; one prints output.

br2 seems redundant. (It prints two breaks, same as (br 2).

I'm planning to write up some documentation on html.arc, but I figured I'd post these comments first.



3 points by almkglor 6059 days ago | link

> If you try to use a tag attribute that Arc doesn't know about, it puts a comment in the HTML <!-- ignoring mytag for a-->. Error reporting in the HTML itself seems like a bad idea.

I think it doesn't - in my experience these warnings occur when I load the file, and are printed on stderr. Not sure though, I haven't actually checked the code.

In any case I'd recommend the use of my w/html macro, in whtml.arc, which IMO is more consistent:

  (w/html
    ('head
      ('title
        (pr "This is My Page!")))
    ('body
      ('h1 (pr "This is My Page!"))
      ('.content
        ('p
          (pr "This is my content!"))
        ('p
          (pr "Another paragraph of my content."))
        ('p
          (pr "The third paragraph of my content!")))
      ('.footer
        (pr "This is where I put my footer string!"))))
.foobar is equivalent to (div class "foobar"), and if you want to put tags with other attributes, just put it in a () form (same syntax as 'tag). So you can create an image by ('(img src "foo.gif"))

w/html also supports the use of #id stuff, but because of the Arc parser, anything that starts with # will not work - you have to either also add a class, or explicitly put the div.

TODO: something like 'tagif.

-----

5 points by cchooper 6059 days ago | link

Consistency: do not expect it! :)

Tag refusing to print attributes it doesn't understand has bitten me a few times. I have my own file adding all the extra attributes I use (you know, really obscure ones like id and onclick).

-----

4 points by almkglor 6059 days ago | link

IMO 'attribute also needs to support * , to specify that a certain attribute is valid for all tags.

  (attribute * id opstring)
  (attribute * class opstring)

-----

1 point by cchooper 6059 days ago | link

Definitely agree there. Almost all the standard attributes are missing from every tag.

-----

3 points by almkglor 6059 days ago | link

Done and on the git.

-----

1 point by kens2 6058 days ago | link

Then the hard-coded support for "style" in all tags can be removed from tag-options and replaced with your new attribute call?

-----

2 points by cchooper 6058 days ago | link

Consistency: almkglor will provide it.

-----

2 points by almkglor 6058 days ago | link

Done and on the git.

^^

As an aside, today is april fool's day in our country now. Happy april fool's!

-----

1 point by almkglor 6058 days ago | link

Done and on the git.

-----

1 point by antiismist 6059 days ago | link

It is true that the html library in standard arc has some inconsistencies. But making a set of macros that generates html the way that you want is super-easy. I would guess that it is easier to write your own set of macros to do it than to read the documentation on how someone else's works.

-----

6 points by eds 6059 days ago | link

But if you don't get the standard library right, then everyone is going to start using their personal version of it, and then you lose portability, etc.

It is worth getting the language right, even if the fix is trivial.

-----

3 points by almkglor 6058 days ago | link

I was actually thinking some time ago about using something like this:

  (mac mapeach (var coll . body)
    "Like 'map, but with 'each syntax"
    `(map1 (fn (,var) ,@body) ,coll))

  (marcup
    `(html
       (head (title ,(+ page-title " - My Website")))
       (body
         (.content
           ,(enformat page-content))
         (.sidebar
           ,@(mapeach (link dest) weblinks
               `(.sidelink (a href= ,dest ,link)))))))
Basically 'marcup would accept a list representing an abstract syntax tree for the HTML code to be generated.

Then I decided to implement w/html instead, which was almost as good ^^; >.< In fact it's arguably better, since the copious ' marks denote non-Arc code (i.e. HTML tags), as opposed to the marcup style above where , marks denote Arc code.

-----