News for hackers. Stuff that matters.
Re:Unsupervised translation of programming languages by userbinator on Tuesday June 09, 2020 @10:19PM (#23473226)
The translator picked up on two idioms of C++ and translated them to more concise forms in Python.

It also either knew about the machine integer representation, or else made a combination of two mistakes that turned out to cancel each other out.

This

    int allocation[n];
    memset(allocation, 42, sizeof(allocation));
    for(int i = 0; i < n; i ++)
would NOT be equivalent to this:

    allocation = [42] * n
    for i in range(n):
Re:Unsupervised translation of programming languages by Animats on Tuesday June 09, 2020 @10:28PM (#23473273)

    Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
    [GCC 8.4.0] on linux
    >>> n = 10
    >>> allocation = [42] * n
    >>> allocation
    [42, 42, 42, 42, 42, 42, 42, 42, 42, 42]
That's what "*" does on lists in Python. The idea is that "abc" + def" is "abcdef", and then they overgeneralized.
Re:Unsupervised translation of programming languages by Hello71 on Tuesday June 09, 2020 @10:33PM (#23473302)

  $ cat test.c
  #include <stdio.h>
  #include <string.h>
  int main() {
      int n = 10;
      int allocation[n];
      memset(allocation, 42, sizeof(allocation));
      for(int i = 0; i < n; i ++)
          printf("%d\n", allocation[i]);
  }
  $ gcc test.c
  $ ./a.out
  707406378
  707406378
  707406378
  707406378
  707406378
  707406378
  707406378
  707406378
  707406378
  707406378
Re:Unsupervised translation of programming languages by lunixbochs on Tuesday June 09, 2020 @10:33PM (#23473301)
memset() is bytewise, the only reason it works with -1 is all the bits are set in every bit width. 0xff repeated still ends up being -1 at int size (0xffffffff). But the byte 0x2a repeated will be something more like 0x2a2a2a2a, which is not equivalent to 0x2a.
Re:Unsupervised translation of programming languages by Animats on Wednesday June 10, 2020 @01:47AM (#23474340)
Right. So the translation was idiomatic but wrong.
Re:Unsupervised translation of programming languages by hoseja on Wednesday June 10, 2020 @08:15AM (#23476232)
I'd say the C++ was wrong/unclear. If you want all the ints in your array to be a certain number, use std::fill. If you want all their bits to be 1, use something like ~0 in the memset.
Re:Unsupervised translation of programming languages by raxxorrax on Wednesday June 10, 2020 @04:12AM (#23475002)
It would be interesting to test this and if they really don't rely on rules, which I would suspect for memset as well as sizeof.