New multiline string non-tailing arguments #1998

Closed
yrashk opened this Issue Jan 15, 2014 · 13 comments

Comments

Projects
None yet
4 participants
Contributor

yrashk commented Jan 15, 2014

It was a very common case for us to write SQL queries this way:

query(db, """, arg: x)
SELECT a,b,c 
  FROM d
  WHERE arg > :{arg}
"""

With the recent changes to heredocs, what's the best way to accomplish this?

Owner

josevalim commented Jan 15, 2014

Two options:

  1. Use var:

    sql = """
    SELECT a,b,c 
      FROM d
      WHERE arg > :{arg}
    """
    query(db, sql, arg: x)
  2. Move to the end

    query(db, """
    SELECT a,b,c 
      FROM d
      WHERE arg > :{arg}
    """, arg: x)
Contributor

yrashk commented Jan 15, 2014

2 doesn't work:

** (SyntaxError) test.ex:8: syntax error before: ','

defmodule A do
  def query(a, b, c), do: {a,b,c}
  def test(x) do
query(db, """
SELECT a,b,c
  FROM d
  WHERE arg > :{arg}
""", arg: x)
  end
end
Contributor

yrashk commented Jan 15, 2014

1 is... weird, don't you think?

Contributor

christhekeele commented Jan 15, 2014

I always kind of liked the continuable multiline string syntax. :/

Christopher Keele
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Wednesday, January 15, 2014 at 1:10 PM, Yurii Rashkovskii wrote:

1 is... weird, don't you think?


Reply to this email directly or view it on GitHub (#1998 (comment)).

Contributor

yrashk commented Jan 15, 2014

Me too
On Jan 15, 2014 12:30 PM, "Christopher Keele" notifications@github.com
wrote:

I always kind of liked the continuable multiline string syntax. :/

Christopher Keele
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Wednesday, January 15, 2014 at 1:10 PM, Yurii Rashkovskii wrote:

1 is... weird, don't you think?


Reply to this email directly or view it on GitHub (
#1998 (comment)).


Reply to this email directly or view it on GitHubhttps://github.com/elixir-lang/elixir/issues/1998#issuecomment-32411638
.

Contributor

manpages commented Jan 15, 2014

Agreed. Was quite a bit surprised to see it deprecated.
On Jan 15, 2014 9:30 PM, "Christopher Keele" notifications@github.com
wrote:

I always kind of liked the continuable multiline string syntax. :/

Christopher Keele
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Wednesday, January 15, 2014 at 1:10 PM, Yurii Rashkovskii wrote:

1 is... weird, don't you think?


Reply to this email directly or view it on GitHub (
#1998 (comment)).


Reply to this email directly or view it on GitHubhttps://github.com/elixir-lang/elixir/issues/1998#issuecomment-32411638
.

Contributor

christhekeele commented Jan 15, 2014

Never appreciated it till I started playing with custom sigils, then I got it.

Christopher Keele
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Wednesday, January 15, 2014 at 3:01 PM, Jonns Mostovoys wrote:

Agreed. Was quite a bit surprised to see it deprecated.
On Jan 15, 2014 9:30 PM, "Christopher Keele" <notifications@github.com (mailto:notifications@github.com)>
wrote:

I always kind of liked the continuable multiline string syntax. :/

Christopher Keele
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Wednesday, January 15, 2014 at 1:10 PM, Yurii Rashkovskii wrote:

1 is... weird, don't you think?


Reply to this email directly or view it on GitHub (
#1998 (comment)).


Reply to this email directly or view it on GitHubhttps://github.com/elixir-lang/elixir/issues/1998#issuecomment-32411638
.


Reply to this email directly or view it on GitHub (#1998 (comment)).

Owner

josevalim commented Jan 15, 2014

The main issue is that it really complicated tokenization and parsing. For example, there were complaints from people saying it was extremely hard to implement in many text editors and highlighters. That's why we decided to deprecate it and move to a more conventional approach.

Contributor

yrashk commented Jan 15, 2014

So, the only reasoning is some editors and highlighters?

Contributor

christhekeele commented Jan 15, 2014

It makes a lot of sense from a syntax consumer standpoint. I just appreciated the clever design. :)

Christopher Keele
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Wednesday, January 15, 2014 at 3:04 PM, José Valim wrote:

The main issue is that it really complicated tokenization and parsing. For example, there were complaints from people saying it was extremely hard to implement in many text editors and highlighters. That's why we decided to deprecate it and move to a more conventional approach.


Reply to this email directly or view it on GitHub (#1998 (comment)).

Owner

josevalim commented Jan 15, 2014

No, the main issue is it really complicated tokenization and parsing, as exactly said in the previous comment. Including of Elixir itself, which ships with a tokenizer and a parser. And that would apply to any other tool, code analysis, coverage handling, etc, that may come up in the future.

Contributor

manpages commented Jan 15, 2014

Can't we make a magical sigil for that? Btw, Joe's operator would be handy
here. Taking Yurii's case as an example

"""
SLECT * FROM users
  WHERE id > ${id}
""" |2> DB.exec(db, id: 1000)

Wdyt?
On Jan 15, 2014 10:14 PM, "José Valim" notifications@github.com wrote:

No, the main issue is it really complicated tokenization and parsing,
as exactly said in the previous comment. Including of Elixir itself, which
ships with a tokenizer and a parser. And that would apply to any other
tool, code analysis, that may come up in the future.


Reply to this email directly or view it on GitHubhttps://github.com/elixir-lang/elixir/issues/1998#issuecomment-32415613
.

Owner

josevalim commented Jan 16, 2014

@manpages Adding that operator is a different discussion and one that we already had in the mailing list. We could start the discussion again but I don't think the outcome would change for now.

josevalim closed this in 54e8ea1 Jan 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment