eo icon indicating copy to clipboard operation
eo copied to clipboard

Can't run program with stdin

Open ivan-egorov42 opened this issue 3 years ago • 8 comments

I tried to run a program from the paper(p.6, 2.10) like this:

[] > hello
  QQ.io.stdout > say
    QQ.txt.sprintf
      "The length of %s is %d"
      QQ.io.stdin.next-line > x!
      x.length

then eoc dataize hello. The problem is that there isn't 'data' attribute, when I run this. I tried to write QQ.io.stdout > @ instead of, but now there is a problem with stdin, I think.

First, I think it would be nice to improve example from paper. Second, I get this error after changing a program:

hello EOorg.EOeolang.EOstringν19="There is no line in the standard input stream to consume"SF

ivan-egorov42 avatar Aug 10 '22 11:08 ivan-egorov42

Update: I realized, that this problem bounds to line with x.length, because program works without x.length(e.g. just x). Maybe there are some problems with x as a string, maybe with stdin. Actually, I don't know

ivan-egorov42 avatar Aug 10 '22 12:08 ivan-egorov42

@ivan-egorov42 It is quite interesting, that such a code works and gives correct answer.

+alias org.eolang.io.stdout
+alias org.eolang.io.stdin
+alias org.eolang.txt.sprintf

[] > hello
  stdout > say
    sprintf
      "The length is %d, the string is %s\n"
      x.length
      stdin.next-line > x!

[] > problem
  hello.say > @

image

includealex avatar Aug 10 '22 13:08 includealex

@includealex That's very funny. Now I have a question, why program works, if we just swapped two lines? (x.length and stdin.next-line > x!)

ivan-egorov42 avatar Aug 10 '22 13:08 ivan-egorov42

I suppose it happens because when eo dataize sprintf, it starts from the last attributes. In common, possibly, it dataize using recursion, that is why it starts from the end. So wnen it firstly tries to dataize x.length it gets null. That's my theory.

levBagryansky avatar Aug 10 '22 14:08 levBagryansky

@ivan-egorov42 I think, that problem is bounded with either stdin or sprintf. Here is a simple test, that shows that swapping lines shouldn't cause an error. swapping-lines

@Graur, @mximp, what do you think about this so-called swapped-lines bug?

includealex avatar Aug 10 '22 16:08 includealex

@includealex @ivan-egorov42 Indeed, it is a bug. You are welcome to fix it

Graur avatar Aug 11 '22 07:08 Graur

@Graur, I'll try to fix this one.

includealex avatar Aug 11 '22 08:08 includealex

@includealex Go ahead

Graur avatar Aug 11 '22 08:08 Graur

@ivan-egorov42 now it works. Please, close the issue.

includealex avatar Sep 16 '22 15:09 includealex

@includealex thanks!)

ivan-egorov42 avatar Sep 20 '22 09:09 ivan-egorov42