jingoo icon indicating copy to clipboard operation
jingoo copied to clipboard

Tset status

Open sagotch opened this issue 6 years ago • 5 comments

The constructor is called Tset, but a set is a collection of unique items.

Tset is definitely more considered as a tuple rather than a set. So we probably should rename this constructor.

I am not sure that tuples are really useful in jingoo. If there really is no benefit from using tuples instead of list, maybe that we could remove this data type in order to keep jinja simpler, remove some conflicts and simplify the parser.

sagotch avatar Feb 10 '19 19:02 sagotch

Tset is not proper name indeed, it must be renamed to Ttuple as you said.

I think Ttuple is useful when we iterate multiple value in for statement, or return multiple value for macro or function.

{# can we write function like this? #}
{% function get_links_for(target) %}
  {% if target == "side-nav" %}
    [("www.foo.com", "foo"), ("www.bar.com", "bar")]
  {% endif %}
{% endfunction %}

<ul>
  {% for (href, title) in get_links_for('side-nav') %}
  <li><a href="{{href}}">{{title}}</a></li>
  {% endfor %}
</ul>

I think it's way easier to understand compared to list only iteration.

tategakibunko avatar Feb 10 '19 22:02 tategakibunko

Well... (a, b) is actually the same as [a, b]. As jingoo's representation of tuple and list are the same. I am not 100% sure that removing tuples is a good choice. We could keep the syntax (I actually did not mean to remove it) but use only one internal representation.

sagotch avatar Feb 10 '19 23:02 sagotch

(a, b) is actually the same as [a, b]

Yes it is, what I mean is that tuple is semantically easy to read compared to nested list iteration.

What I throught is...

{% for (href, title) in [("foo.com", "foo"), ("bar.com", "bar")] %}

is easy to read than

{# nested list is hard to read for me.... #}
{% for [href, title] in [["foo.com", "foo"], ["bar.com", "bar"]] %}

tategakibunko avatar Feb 10 '19 23:02 tategakibunko

But we should define Ttuple only for readability maybe controversy.

Is this syntax hard for your new mly parser?

EDIT: Ahh, if we treat the tuple as list internally, we can remove Tset, is that your point?

tategakibunko avatar Feb 10 '19 23:02 tategakibunko

Is this syntax hard for your new mly parser?

No, it's a problem that was already present and it's the only conflict that I did not resolved yet:

The conflict is: in {{ 3 is foo (a,b,c) }}, is (a,b,c) a tuple, or 3 arguments (since we do not need parenthesis if only one extra argument is need.

It's not a real problem and it it here since the beggining.

Ahh, if we treat the tuple as list internally, we can remove Tset, is that your point?

Yes it is :+1:

EDIT: This actually would not simplify the parser, but Jg_types, Jg_runtime, and maybe Jg_interp.

sagotch avatar Feb 11 '19 07:02 sagotch