[Suggestion] Define t[[[]]] to index t with a long string

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[Suggestion] Define t[[[]]] to index t with a long string

Soni "They/Them" L.
I sometimes don't want to escape strings (so that the human reader can
read them literally instead of trying to figure out the escapes), and
adding spaces around the long strings just doesn't look as good. t[[[]]]
is currently a syntax error and t[[===[]===]] is currently a function call.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Paul K-2
> t[[[]]] is currently a syntax error and t[[===[]===]] is currently a function call.

I think t[ [[]] ] will do.

Paul.

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Nagaev Boris
In reply to this post by Soni "They/Them" L.
On Fri, Oct 9, 2015 at 1:00 AM, Soni L. <[hidden email]> wrote:
> I sometimes don't want to escape strings (so that the human reader can read
> them literally instead of trying to figure out the escapes), and adding
> spaces around the long strings just doesn't look as good. t[[[]]] is
> currently a syntax error and t[[===[]===]] is currently a function call.
>
> --
> Disclaimer: these emails may be made public at any given time, with or
> without reason. If you don't agree with this, DO NOT REPLY.
>

t[[[xxx]]] is parsed as t [[ [xxx ]] and ]. String is started with
first occurrence of [[ and is ended with first occurrence ]].



--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Nagaev Boris
In reply to this post by Paul K-2
On Fri, Oct 9, 2015 at 1:08 AM, Paul K <[hidden email]> wrote:
>> t[[[]]] is currently a syntax error and t[[===[]===]] is currently a function call.
>
> I think t[ [[]] ] will do.
>
> Paul.
>

Soni said "adding spaces around the long strings just doesn't look as good".


--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Paul K-2
 > Soni said "adding spaces around the long strings just doesn't look as good".

Right ;). t[([[]])] should work for those disliking spaces. He didn't
say anything about disliking parentheses.

Paul.

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Soni "They/Them" L.


On 08/10/15 07:16 PM, Paul K wrote:
>   > Soni said "adding spaces around the long strings just doesn't look as good".
>
> Right ;). t[([[]])] should work for those disliking spaces. He didn't
> say anything about disliking parentheses.
>
> Paul.
>
[([[ still doesn't look as good as [[[ because '(' is round while '[' is
square. ("you got a round thingy in the middle of the square thingies.")

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Nagaev Boris
On Fri, Oct 9, 2015 at 1:25 AM, Soni L. <[hidden email]> wrote:

>
>
> On 08/10/15 07:16 PM, Paul K wrote:
>>
>>   > Soni said "adding spaces around the long strings just doesn't look as
>> good".
>>
>> Right ;). t[([[]])] should work for those disliking spaces. He didn't
>> say anything about disliking parentheses.
>>
>> Paul.
>>
> [([[ still doesn't look as good as [[[ because '(' is round while '[' is
> square. ("you got a round thingy in the middle of the square thingies.")
>
>
> --
> Disclaimer: these emails may be made public at any given time, with or
> without reason. If you don't agree with this, DO NOT REPLY.
>
>

t[[[z]]] looks ambiguous. Everybody would have to remember what it
means: t("z") or t["z"].

--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Coda Highland
In reply to this post by Soni "They/Them" L.
On Thu, Oct 8, 2015 at 3:25 PM, Soni L. <[hidden email]> wrote:

>
>
> On 08/10/15 07:16 PM, Paul K wrote:
>>
>>   > Soni said "adding spaces around the long strings just doesn't look as
>> good".
>>
>> Right ;). t[([[]])] should work for those disliking spaces. He didn't
>> say anything about disliking parentheses.
>>
>> Paul.
>>
> [([[ still doesn't look as good as [[[ because '(' is round while '[' is
> square. ("you got a round thingy in the middle of the square thingies.")

You got your square thingies in my round thingies!

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Christian Thaeter
In reply to this post by Soni "They/Them" L.


On 2015-10-08 19:25, Soni L. wrote:

>
>
> On 08/10/15 07:16 PM, Paul K wrote:
> >   > Soni said "adding spaces around the long strings just doesn't
> >   > look as good".
> >
> > Right ;). t[([[]])] should work for those disliking spaces. He
> > didn't say anything about disliking parentheses.
> >
> > Paul.
> >
> [([[ still doesn't look as good as [[[ because '(' is round while '['
> is square. ("you got a round thingy in the middle of the square
> thingies.")

t = setmetatable(t, {
  __call = function(_, i) return t[i] end
})

print(t[[look Ma', less round and square thingies]]


.. yes I know thats not sufficient for all cases, making something
like
 t[[newindex]] = blah
working is left for the reader.

        Christian

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Thomas Jericke
In reply to this post by Nagaev Boris
On 10/09/2015 12:48 AM, Nagaev Boris wrote:
>
> t[[[z]]] looks ambiguous. Everybody would have to remember what it
> means: t("z") or t["z"].
>
t[[z]] is t("z") so t[[[]]] would actually be t("[]"), wouldn't it?
--
Thomas

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Rena

On Oct 9, 2015 6:41 AM, "Thomas Jericke" <[hidden email]> wrote:
>
> On 10/09/2015 12:48 AM, Nagaev Boris wrote:
>>
>>
>> t[[[z]]] looks ambiguous. Everybody would have to remember what it
>> means: t("z") or t["z"].
>>
> t[[z]] is t("z") so t[[[]]] would actually be t("[]"), wouldn't it?
> --
> Thomas
>

Yeah, this syntax is ambiguous. t [[[z]]] already looks like it could be parsed as one of:
t["z"] -- replacing innermost [[]] with ""
t"[z"] -- replacing first [[ and ]] with ""
t"[z]" -- replacing outermost [[]] with ""

As far as neatness, I think spaces improve it a lot here by clearly defining the intended meaning:
t[ [[z]] ] -- or even:
t[
    [[some long string here]]
]
But of course spaces don't matter to the compiler.

My solution if I were presented with this situation would be one of:
local s=[[z]]
X = t[s]
Or: refactor so that indexing a table with a string that doesn't fit nicely in quotes is no longer necessary. :)

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Coda Highland
On Fri, Oct 9, 2015 at 4:17 AM, Rena <[hidden email]> wrote:

> On Oct 9, 2015 6:41 AM, "Thomas Jericke" <[hidden email]> wrote:
>>
>> On 10/09/2015 12:48 AM, Nagaev Boris wrote:
>>>
>>>
>>> t[[[z]]] looks ambiguous. Everybody would have to remember what it
>>> means: t("z") or t["z"].
>>>
>> t[[z]] is t("z") so t[[[]]] would actually be t("[]"), wouldn't it?
>> --
>> Thomas
>>
>
> Yeah, this syntax is ambiguous. t [[[z]]] already looks like it could be
> parsed as one of:
> t["z"] -- replacing innermost [[]] with ""
> t"[z"] -- replacing first [[ and ]] with ""
> t"[z]" -- replacing outermost [[]] with ""
>
> As far as neatness, I think spaces improve it a lot here by clearly defining
> the intended meaning:
> t[ [[z]] ] -- or even:
> t[
>     [[some long string here]]
> ]
> But of course spaces don't matter to the compiler.
>
> My solution if I were presented with this situation would be one of:
> local s=[[z]]
> X = t[s]
> Or: refactor so that indexing a table with a string that doesn't fit nicely
> in quotes is no longer necessary. :)

Spaces DO matter to the compiler. It may recognize some tokens without
whitespace in between, but it most certainly does NOT allow whitespace
WITHIN a token.

Besides, I don't know if anyone's actually TESTED what Lua does here.
I just did:

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print[[[x]]]
stdin:1: unexpected symbol near ']'
> print[[ [x] ]]
 [x]

In other words, the parse it ACTUALLY takes is: print"[x"]

This comes to no surprise to me because I've written a compiler
before; the lexer is doing greedy matching, extracting the longest
token it can from the stream.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Soni "They/Them" L.
In reply to this post by Rena


On 09/10/15 08:17 AM, Rena wrote:

>
> On Oct 9, 2015 6:41 AM, "Thomas Jericke" <[hidden email]
> <mailto:[hidden email]>> wrote:
> >
> > On 10/09/2015 12:48 AM, Nagaev Boris wrote:
> >>
> >>
> >> t[[[z]]] looks ambiguous. Everybody would have to remember what it
> >> means: t("z") or t["z"].
> >>
> > t[[z]] is t("z") so t[[[]]] would actually be t("[]"), wouldn't it?
> > --
> > Thomas
> >
>
> Yeah, this syntax is ambiguous. t [[[z]]] already looks like it could
> be parsed as one of:
> t["z"] -- replacing innermost [[]] with ""
> t"[z"] -- replacing first [[ and ]] with ""
> t"[z]" -- replacing outermost [[]] with ""
>
> As far as neatness, I think spaces improve it a lot here by clearly
> defining the intended meaning:
> t[ [[z]] ] -- or even:
> t[
>     [[some long string here]]
> ]
> But of course spaces don't matter to the compiler.
>
> My solution if I were presented with this situation would be one of:
> local s=[[z]]
> X = t[s]
> Or: refactor so that indexing a table with a string that doesn't fit
> nicely in quotes is no longer necessary. :)
>
Table initialization.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Dirk Laurie-2
In reply to this post by Soni "They/Them" L.
2015-10-09 0:00 GMT+02:00 Soni L. <[hidden email]>:

> adding spaces around the long strings just doesn't look as good

Rather subjective. Would you also claim that `x = y` just doesn't look
as good as `x=y`?

Using spaces, including blank lines and indentation, to make the
meaning of a program clearer looks good to me. So why complain
when even the compiler would be confused?

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

彭 书呆
In reply to this post by Soni "They/Them" L.
在 2015/10/9 6:00, Soni L. 写道:
> I sometimes don't want to escape strings (so that the human reader can read them literally instead of trying to figure out the escapes), and adding spaces around the long strings just doesn't look as good. t[[[]]] is currently a syntax error and t[[===[]===]] is currently a function call.
>

if you were a C++ guy, you'd be very familiar with code such as (note the spaces between the '>'s):

    std::vector<std::pair<std::string, std::list<int> > >  my_array;

the spaces are needed to help the lexer's disambiguation.


--
the nerdy Peng / 书呆彭 / Sent from Thunderbird



Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Coda Highland
On Fri, Oct 9, 2015 at 9:09 PM, 书呆彭, Peng Yi <[hidden email]> wrote:

> 在 2015/10/9 6:00, Soni L. 写道:
>>
>> I sometimes don't want to escape strings (so that the human reader can
>> read them literally instead of trying to figure out the escapes), and adding
>> spaces around the long strings just doesn't look as good. t[[[]]] is
>> currently a syntax error and t[[===[]===]] is currently a function call.
>>
>
> if you were a C++ guy, you'd be very familiar with code such as (note the
> spaces between the '>'s):
>
>    std::vector<std::pair<std::string, std::list<int> > >  my_array;
>
> the spaces are needed to help the lexer's disambiguation.

That wart has been fixed in C++ for four years now.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Christian Thaeter
In reply to this post by Soni "They/Them" L.


On 2015-10-08 19:00, Soni L. wrote:

> I sometimes don't want to escape strings (so that the human reader
> can read them literally instead of trying to figure out the escapes),
> and adding spaces around the long strings just doesn't look as good.
> t[[[]]] is currently a syntax error and t[[===[]===]] is currently a
> function call.

late idea, what comes in mind for a lua-ish syntax is that functions
already accept strings (and tables) without parentheses. I think this
could be applied to indexing without syntax ambiguity:

 foo = {}
 foo.bar = "as usual, syntactic sugar for foo['bar']"
 foo."string here" = "syntactic sugar for foo['string here']"
 foo.[[Then working with long strings shouldn't be any trouble]] = ".."

        Christian

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Nagaev Boris
In reply to this post by Coda Highland
On Sat, Oct 10, 2015 at 7:10 AM, Coda Highland <[hidden email]> wrote:

> On Fri, Oct 9, 2015 at 9:09 PM, 书呆彭, Peng Yi <[hidden email]> wrote:
>> 在 2015/10/9 6:00, Soni L. 写道:
>>>
>>> I sometimes don't want to escape strings (so that the human reader can
>>> read them literally instead of trying to figure out the escapes), and adding
>>> spaces around the long strings just doesn't look as good. t[[[]]] is
>>> currently a syntax error and t[[===[]===]] is currently a function call.
>>>
>>
>> if you were a C++ guy, you'd be very familiar with code such as (note the
>> spaces between the '>'s):
>>
>>    std::vector<std::pair<std::string, std::list<int> > >  my_array;
>>
>> the spaces are needed to help the lexer's disambiguation.
>
> That wart has been fixed in C++ for four years now.
>
> /s/ Adam
>

It was fixed in C++ because it is not ambigous for a programmer (not
for a parser). The construction being discussed t[[[]]] is ambiguous
for a programmer.

--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Coda Highland
On Sat, Oct 10, 2015 at 12:19 PM, Nagaev Boris <[hidden email]> wrote:

> On Sat, Oct 10, 2015 at 7:10 AM, Coda Highland <[hidden email]> wrote:
>> On Fri, Oct 9, 2015 at 9:09 PM, 书呆彭, Peng Yi <[hidden email]> wrote:
>>> 在 2015/10/9 6:00, Soni L. 写道:
>>>>
>>>> I sometimes don't want to escape strings (so that the human reader can
>>>> read them literally instead of trying to figure out the escapes), and adding
>>>> spaces around the long strings just doesn't look as good. t[[[]]] is
>>>> currently a syntax error and t[[===[]===]] is currently a function call.
>>>>
>>>
>>> if you were a C++ guy, you'd be very familiar with code such as (note the
>>> spaces between the '>'s):
>>>
>>>    std::vector<std::pair<std::string, std::list<int> > >  my_array;
>>>
>>> the spaces are needed to help the lexer's disambiguation.
>>
>> That wart has been fixed in C++ for four years now.
>>
>> /s/ Adam
>>
>
> It was fixed in C++ because it is not ambigous for a programmer (not
> for a parser). The construction being discussed t[[[]]] is ambiguous
> for a programmer.
>

Oh, I know. The point is that the C++ example isn't particularly
applicable to the discussion at hand.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: [Suggestion] Define t[[[]]] to index t with a long string

Axel Kittenberger
In reply to this post by Soni "They/Them" L.
and adding spaces around the long strings just doesn't look as good
Suggestion:considerspacingtobeagoodthing.ithelpsstructuringstuffandiseasyoneyes.google"negativspace"whypeoplespecializingondesignconsideremptyspacetobeagoodthingtm.

On Fri, Oct 9, 2015 at 12:00 AM, Soni L. <[hidden email]> wrote:
I sometimes don't want to escape strings (so that the human reader can read them literally instead of trying to figure out the escapes), and adding spaces around the long strings just doesn't look as good. t[[[]]] is currently a syntax error and t[[===[]===]] is currently a function call.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.



12