Arc Forumnew | comments | leaders | submitlogin
Wart update: ssyntax, new splice operator instead of apply, pointer comparison
3 points by akkartik 4608 days ago | 8 comments
Like Pauan said[1], it's indeed looking punctuation-heavy: http://github.com/akkartik/wart/blob/1f7f6dc405/020.wart

Hopefully it'll start looking more sane past the core of the language.

---

ssyntax follows the same precedence as arc, but you can do things like this:

  car:,$f
..which expands to (car ,$f) [2]

---

apply has been replaced with eight's splice operator[3]. What used to be this:

  (apply f args)
now becomes this:

  (f @args)
In this expression, args is evaluated and spliced into the expression, but f doesn't evaluate it's args a second time. All the arguments were thus evaluated just once, even if f quotes some of its params[4].

  def foo(x 'y)
    cons x y

  with (a 1 b 2)
    foo a b

  => (1 . b)

  with (a 1 b 2)
    foo @'(a b)

  => (a . b)

  with (a 1 b 2)
    foo @(list a b)

  => (1 . 2)
---

The splice operator permits more than apply because args to be spliced don't have to come at the end:

  (foo @list.a b)
---

On my todo list is to figure out a way to replace ,@ with @, and thereby reduce the number of primitives by 1.

---

The addr function enables pointer comparison[5]:

  (iso '(1 2) '(1 2)) ; true like lisp's equal

  (iso (addr '(1 2)) (addr '(1 2))) ; false like lisp's eq
---

[1] http://arclanguage.org/item?id=15143

[2] $ is the implicit gensym operator: http://arclanguage.org/item?id=13342

[3] The * operator at http://github.com/diiq/eight/blob/master/README

[4] Like eight and unlike either lisp or scheme, wart lets functions selectively evaluate just some of their formal parameters. To leave a param unevaluated, just quote it like in the examples above.

[5] http://arclanguage.org/item?id=13698



1 point by Pauan 4608 days ago | link

"apply has been replaced with the @ splice operator. What used to be this:"

This is one of the things I've wanted myself in Arc. The ability to splice things in without needing quasiquote is quite nice.

---

"On my todo list is to figure out a way to replace ,@ with @, and thereby reduce the number of primitives by 1."

I'm probably misunderstanding the problem, but what about this?

  (foo '@(list a b c))

-----

1 point by akkartik 4608 days ago | link

Is that inside a quasiquote? I don't follow.

-----

2 points by Pauan 4608 days ago | link

Hm... I assume you're talking about getting rid of the "unquote-splicing" operator. If so, then why can't you do that right now?

  `(foo ,@(list a b c))
Would expand into this:

  (quasiquote (foo (unquote (splicing a b c))))
I'm not entirely sure what the problem is, as to why you can't replace ,@ with @

-----

1 point by akkartik 4608 days ago | link

Holy smokes, you're right!

Update No now I'm confused again. When I see:

  `(cons ,@(list 1 2))
I read it as:

  eval (list 1 2)
  splice it in (to what?)
  insert it into the backtick
When I see:

  `(cons @,(list 1 2))
I read it as:

  eval (list 1 2)
  insert it into the backtick (as say x)

  then at eval time, eval (cons @x)
Neither seems quite what I want.

-----

1 point by Pauan 4608 days ago | link

"`(cons ,@(list 1 2))"

I would assume that it is splicing it into the list. In other words, it would evaluate into this list:

  (cons 1 2)
But I don't know how you're implementing splicing, so I'm not sure how much I can help.

---

"Neither seems quite what I want."

Why not? Both seem to end up as the same end result as you would get in Arc, right?

-----

1 point by akkartik 4608 days ago | link

Yeah I want it to splice it into the list. That's what it does right now. But it takes a special-case. I'm having trouble figuring out how it would work if I removed the special-case from tokenize, parse, and eval. I'm not sure that the behavior of ,@ can be boiled down to just , and @. It should be independent of my implementation.

Perhaps I should just try it, see what happens.

-----

3 points by rocketnia 4607 days ago | link

I think it's kinda intuitive for `(foo ,@(list 1 2)) to expand to (quasiquote (foo (unquote 1 2))). If unquote takes multiple subexpressions, as it does in Common Lisp (http://arclanguage.org/item?id=9912), this can evaluate to (foo 1 2).

However, I really think this should be considered part of the behavior of 'quasiquote. Just like 'unquote has no meaning except as interpreted by 'quasiquote, it's fine for @ to have no meaning except as interpreted by function calls and 'quasiquote.

Hmm... if you say `@(list 1 2), does that pass (splicing (list 1 2)) or something to 'quasiquote, or does it actually pass 1 and 2? If I were trying to accomplish @ with fexprs, I think I'd prefer the former, and I'd treat regular functions/applicatives as though they were fexprs that expanded (splicing ...) manually.

-----

1 point by Pauan 4608 days ago | link

"Perhaps I should just try it, see what happens."

Yeah, that would be my suggestion.

-----