Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read objects with dots? #2751

Closed
volodya-lombrozo opened this issue Dec 28, 2023 · 22 comments
Closed

How to read objects with dots? #2751

volodya-lombrozo opened this issue Dec 28, 2023 · 22 comments
Labels
Milestone

Comments

@volodya-lombrozo
Copy link
Member

volodya-lombrozo commented Dec 28, 2023

I received the following eo code:

$
.foo
  .a
.plus
  1

It should be something like this.a.foo() + 1 in java. To be honest, I just can't understand if I received the correct output. How should I read eo objects with dots in the beginning?
Maybe you can add some examples to the README?

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Could you help here?

@maxonfjvipon
Copy link
Member

@volodya-lombrozo I think we can write a blog post about it where we can explain syntax notations in EO.

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Could you help me here for now, please? It's kind of urgent.

@maxonfjvipon
Copy link
Member

@volodya-lombrozo we have 4 notations for methods. For this.a.foo() + 1 it would be:

  1. horizontal
$.a.foo.plus 1
  1. vertical
$
.a
.foo
.plus
  1
  1. reversed horizontal
plus. (foo. (a. $)) 1
  1. reversed vertical
plus.
  foo.
    a.
      $
  1

You output is not really correct

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Thanks

@maxonfjvipon
Copy link
Member

@volodya-lombrozo let me know if you have any more questions

@volodya-lombrozo
Copy link
Member Author

volodya-lombrozo commented Dec 28, 2023

@maxonfjvipon If I have 1 + 2, what should I get:

 <o base="plus">
      <o base="int" data="bytes">00 00 00 00 00 00 00 01</o>
      <o base="int" data="bytes">00 00 00 00 00 00 00 02</o>
 </o>

or

 <o base=".plus">
      <o base="int" data="bytes">00 00 00 00 00 00 00 01</o>
      <o base="int" data="bytes">00 00 00 00 00 00 00 02</o>
</o>

@yegor256
Copy link
Member

@volodya-lombrozo it's the second option:

<o base=".plus">
      <o base="int" data="bytes">00 00 00 00 00 00 00 01</o>
      <o base="int" data="bytes">00 00 00 00 00 00 00 02</o>
</o>

@volodya-lombrozo
Copy link
Member Author

@yegor256 Ok, then I confused. For the this.a.foo() + 1 I got the following XMIR:

<o base=".plus">
    <o base=".intValue">
       <o base="$"/>
       <o base=".a"/>
    </o>
    <o base="int" data="bytes">00 00 00 00 00 00 00 01</o>
</o>

And it seems correct to me according with your answer. But this XMIR is represented as follows:

tuple
  $
  .intValue
    .a
  .plus
    1

@yegor256
Copy link
Member

@volodya-lombrozo don't you miss the method attribute? I think you got this:

<o base=".plus">
    <o base=".intValue">
       <o base="$"/>
       <o base=".a" method=""/> <!-- here! -->
    </o>
    <o base="int" data="bytes">00 00 00 00 00 00 00 01</o>
</o>

@yegor256
Copy link
Member

yegor256 commented Dec 28, 2023

@volodya-lombrozo simply put, this:

<o base="a"/>
<o base=".foo" method=""/>

is the same as:

<o base=".foo">
  <o base="a"/>
</o>

The parser produces the first form, while a special XSL transformation turns it into the second one: https://github.com/objectionary/eo/blob/master/eo-parser/src/main/resources/org/eolang/parser/wrap-method-calls.xsl

It's a technical limitation of the parser, we can't overcome it :(

@volodya-lombrozo
Copy link
Member Author

@yegor256 Since I don't use wrap-method-calls.xsl, adding method attribute won't help me.

@yegor256
Copy link
Member

@volodya-lombrozo you should use it, I believe. You should not work with the XMIR produced by the parser without optimizations provided by the eo:optimize mojo.

@volodya-lombrozo
Copy link
Member Author

volodya-lombrozo commented Dec 28, 2023

@yegor256 So, I have to receive the following XMIR:

<o base=".plus">
    <o base=".intValue">
      <o base=".a">
        <o base="$"/> 
      </o>    
    </o>
    <o base="int" data="bytes">00 00 00 00 00 00 00 01</o>
</o>

for this.a.foo() + 1 ?

@volodya-lombrozo
Copy link
Member Author

volodya-lombrozo commented Dec 28, 2023

@volodya-lombrozo you should use it, I believe. You should not work with the XMIR produced by the parser without optimizations provided by the eo:optimize mojo.

@yegor256 I don't use the parser either. I'm trying to construct XMIR from bytecode instructions.

@yegor256
Copy link
Member

@volodya-lombrozo yes, this is correct:

<o base=".plus">
    <o base=".intValue">
      <o base=".a">
        <o base="$"/> 
      </o>    
    </o>
    <o base="int" data="bytes">00 00 00 00 00 00 00 01</o>
</o>

@maxonfjvipon
Copy link
Member

It's a technical limitation of the parser, we can't overcome it :(

@yegor256 I think maybe we actually can... let me inverstigate

@maxonfjvipon maxonfjvipon added this to the Routine milestone Feb 2, 2024
@yegor256
Copy link
Member

@volodya-lombrozo still a bug?

@volodya-lombrozo
Copy link
Member Author

@yegor256 I believe we need to add some docs about method-wraps and dot notation. Otherwise, somebody else will face with the same question again.

@yegor256
Copy link
Member

@volodya-lombrozo this mechanism is explained here: https://news.eolang.org/2022-11-25-xmir-guide.html (see the "methods" section)

@volodya-lombrozo
Copy link
Member Author

@yegor256 First of all, this link is far from the repository. When you close this ticket, I will loose it immediately.
Moreover, it's a blog post, not official documentation. I believe a blog post is typically informal and narrative, aimed at engaging readers with stories, opinions, or updates. Documentation is formal and structured, designed to provide clear instructions, guidelines, or reference information for using a product or system. So, when I read a "blog post", I just have no trust to it.

@yegor256
Copy link
Member

@volodya-lombrozo I agree, we'll deal with it in #3375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants