Arc Forumnew | comments | leaders | submitlogin
1 point by jazzdev 5298 days ago | link | parent

It makes me a bit paranoid about using quasiquote

This isn't particular to quasiquote. You can reach into any function that returns a literal cons or string.

If this is something you don't want to fix, I'll agree with you there

Yeah, I'm disinclined to try to emulate Arc precisely in this regard because it appears to be an arbitrary artifact of how Arc does quasiquote expansion, and not a defined feature.



2 points by fallintothis 5298 days ago | link

Yeah, I'm disinclined to try to emulate Arc precisely in this regard because it appears to be an arbitrary artifact of how Arc does quasiquote expansion, and not a defined feature.

I think the only thing going on here is quotation. Generally, quoted things work like pointers (see http://arclanguage.org/item?id=10248). Because you can still do

  arc> (def foo () '(1)) ; note: just quote, no quasiquote
  #<procedure: foo>
  arc> (= ((foo) 0) 2)
  2
  arc> (foo)
  (2)
but

  arc> (def foo () (cons 1 nil)) ; note: cons creates new data each call
  *** redefining foo
  #<procedure: foo>
  arc> (= ((foo) 0) 2)
  2
  arc> (foo)
  (1)
Then, the reason the quasiquoted thing gets weird results with the qq.arc I ported is that optimizing `(1) manages to switch between always consing new data with (list '1) and trying to reduce runtime consing with '(1).

-----

1 point by jazzdev 5297 days ago | link

I'm not (terribly) surprised that the ability to modify literals was intentional. Thanks for that link. I'm still wondering if `(1) expanding to '(1) is intentional or not.

Clearly '(foo) is a literal and `(foo ,bar) is not a literal, right? I guess it's not a huge stretch to say that `(foo) is a literal. Unfortunately, qq-expand doesn't always expand `(...) with no commas into '(...)

  Jarc> (qq-expand '(foo))
  (quote (foo))  ; literal
  Jarc> (qq-expand '(foo bar))
  (quote (foo bar)) ; literal
  Jarc> (qq-expand '(foo nil))
  (list (quote foo) nil) ; not a literal
But Arc does expand `(foo nil) into a literal

  arc> (def foo(s) (let a `(3 nil) (= (car a) (cons s (car a)))))
  #<procedure: foo>
  arc> (foo 2)
  (2 . 3)
  arc> (foo 1)
  (1 2 . 3)

-----

2 points by aw 5296 days ago | link

I'm still wondering if `(1) expanding to '(1) is intentional or not.

A quasiquote expander can expand `(1) into '(1) or (list 1), or even (join '(1) ' nil), which is what Bawden's simple, correct, but inefficient quasiquote expander does.

The expander may choose '(1) as being more efficient than (list 1), but isn't required to do so to be a quasiquote expander.

Since it's an optimization, I wouldn't write code that relies on a particular instance of `(1) evaluating to the same list every time, that's just an accidental result of the optimization. Instead, use a plain quote for that.

-----

1 point by fallintothis 5297 days ago | link

That's a bug. It didn't think that nil was a constant. Apparently I didn't know about literal 327 days ago. Thanks for finding it. :)

http://bitbucket.org/fallintothis/qq/changeset/6c0dab5f091e

(Really, all of that code needs a good rewrite. It was straight-ported from some Common Lisp, and suffers greatly for it. Bleh.)

-----

3 points by fallintothis 5296 days ago | link

There. Just updated qq.arc, removing almost 100 lines of cruft in the process. It still passes all the old tests, and (with any luck) is much more pleasant to work with.

http://bitbucket.org/fallintothis/qq/src/tip/qq.arc

-----

2 points by aw 5296 days ago | link

Yay!

-----

1 point by rocketnia 5298 days ago | link

This isn't particular to quasiquote. You can reach into any function that returns a literal cons or string.

I know, hence why I talked about 'quote. On principle, I'm equally paranoid about 'quote, 'quasiquote, and literal strings, but I've never mutated strings in my own projects, and I almost exclusively quasiquote my "escaping" cons cells rather than quoting them, so I just glossed over those facets of my paranoia. :-p

it appears to be an arbitrary artifact of how Arc does quasiquote expansion, and not a defined feature.

Like I said, I think there's a relevant pg comment around here somewhere. I've searched some more, but I still can't find it. Maybe it was just my imagination. ^_^;

Oh, wait, fallintothis's post links to it.

Arrgh, it would help if Google weren't so inconsistent. It's a result for ("behavior can be quite useful in some contexts"), but it doesn't show up in the results for ("behavior can be quite useful in some"), and ("can be quite useful in some contexts") has no results at all. Of course, observing this property and posting about it will no doubt change the search results. XD

Ah, here we go, http://af.searchyc.com/ is much nicer. ^_^

-----