Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 5052 days ago | link | parent

Hmm, could we get rid of the $s and the fns? Not as is, of course, but it's the first thing the eye notices.

I suppose ssyntax helps: $!body, etc.



1 point by evanrmurphy 5052 days ago | link

Yeah, I see what you mean. :) Here are a few macros to combat the jQuery cruft:

  (mac ready body
    ($ (fn () @body)))

  (mac trigger (selector event args...)
    (. ($ selector) (event @args)))

  ; same macro as from http://arclanguage.org/item?id=13776
  ; but redefined in terms of the more general trigger

  (mac draw body
    (trigger 'body html @body))

  (mac handler (selector event body...)
    (trigger selector event (fn ()
      @body)))
And the example re-written using them:

  (ready
    (draw
      (+ (<input>) (<button> "submit")))
    (handler 'button click
      (= said (trigger 'input val))
      (draw 
        (<a> href '# "click here"))
      (handler 'a click
        (draw (+ "you said: " said))))))))
Do you think this is an improvement?

---

Probably the next biggest eyesore would be all the '<' and '>' characters from the html utils. You could make convenience aliases for those (e.g. input for <input> and button for <button>), and then it would look even more fluid:

  (ready
    (draw
      (+ (input) (button "submit")))
    (handler 'button click
      (= said (trigger 'input val))
      (draw 
        (a href '# "click here"))
      (handler 'a click
        (draw (+ "you said: " said))))))))

-----

1 point by evanrmurphy 5051 days ago | link

It looks like our draw macro might as well have the + string concatentation included:

  (mac draw body
    (trigger 'body html 
      (+ @body)))
Then we get even shorter:

  (ready
    (draw (input)
          (button "submit"))
    (handler 'button click
      (= said (trigger 'input val))
      (draw (a href '#
              "click here"))
      (handler 'a click
        (draw "you said: " said)))))))

-----

1 point by akkartik 5051 days ago | link

Yeah, these are certainly looking better. The crux is whether these primitives are part of a basis set (and so don't count against the token count), and whether the rest of the framework is similarly terse (no reason it can't be).

-----