Arc Forumnew | comments | leaders | submitlogin
5 points by mdemare 5920 days ago | link | parent

Sometimes, I'm building a list, and want to include an item in the middle only if a condition is true.

    # Ruby 1.8
    insertion = new? ? ['new'] : []
    list = ['hello','brave'] + insertion + ['world']

    # Ruby 1.9
    insertion = new? ? ['new'] : []
    list = ['hello','brave',*insertion,'world']

    # Arc now
    (let insertion (if (is-new) (list "new") nil)
      (join (list "hello" "brave") insertion (list "world")))

    # With @ operation
    (let insertion (if (is-new) (list "new") nil)
      (list "hello" "brave" @insertion "world"))
I think it's worth it.


3 points by shiro 5919 days ago | link

To build a list, you can already use quasiquote---a standard idiom in Lisp-family languages.

    (let insetion (if (is-new) (list "new") nil)
       `("hello" "brave" ,@insertion "world"))
What matters is to expand a given list into an argument list. To do that you have to use 'apply' now.

-----