digitalmars.D.learn - What do you think about using Chat GPT to create functions in D?
- Marcone (14/14) Apr 03 2023 What do you think about using Chat GPT to create functions in D?
- cgenie (13/13) Apr 03 2023 I once tested ChatGPT to generate Common Lisp code (a simple
- Guillaume Piolat (6/7) Apr 04 2023 Well you can use GitHub Copilot in VSCode, and it is kind of
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (84/99) Apr 14 2023 Recently, it helped me figure out an OpenGL task using d.
What do you think about using Chat GPT to create functions in D? I asked Chat-GPT to create a function in D that was similar to the rsplit() function in Python. It returned this code to me: import std.algorithm; import std.array; import std.string; string[] rsplit(string input, string separator, size_t maxsplit = size_t.max) { auto splitter = splitter(input, separator, SplitterFlag.all); auto results = splitter.array; if (maxsplit < results.length - 1) results = results[results.length - maxsplit - 1 .. $]; return results; }
Apr 03 2023
I once tested ChatGPT to generate Common Lisp code (a simple Redis client). They had a warning that this is not a code generation tool nevertheless it tried to do so. All the code it had was incorrect: it imported foreign libraries that didn't exist and when I complained about it, it apologized and then proposed other libraries that didn't exist. Overall I had the impression that I'm working with some dumb person who pasted me stuff from stackoverflow that seemed to solve my issue. Let me mention that I once asked ChatGPT what is 11 plus 11 and when it responded 22, I told it that it's wrong, it should be 30. It apologized and said that I'm right, it's 30. I tried to do the same experiment again after one day to show off my friends, but it became more resilient to such suggestions.
Apr 03 2023
On Monday, 3 April 2023 at 23:38:52 UTC, Marcone wrote:What do you think about using Chat GPT to create functions in D?Well you can use GitHub Copilot in VSCode, and it is kind of interesting but at the current time seems like a distracting waste of time. It will probably get more useful in a few years. LLMs repeats commonly accepted lies as gospel, so do not expect a well adjusted human-like opinion on anything.
Apr 04 2023
On Monday, 3 April 2023 at 23:38:52 UTC, Marcone wrote:What do you think about using Chat GPT to create functions in D? I asked Chat-GPT to create a function in D that was similar to the rsplit() function in Python. It returned this code to me: import std.algorithm; import std.array; import std.string; string[] rsplit(string input, string separator, size_t maxsplit = size_t.max) { auto splitter = splitter(input, separator, SplitterFlag.all); auto results = splitter.array; if (maxsplit < results.length - 1) results = results[results.length - maxsplit - 1 .. $]; return results; }Recently, it helped me figure out an OpenGL task using d. This is the code it suggests after I provide some details to it about the case and the error I get: ```d Slice!(RCI!ubyte, 3LU, Contiguous) plot2imslice() nogc nothrow { import mir.rc; Slice!(RCI!ubyte, 3LU, Contiguous) imgslice = rcslice!ubyte([height, width, 3], 0); glfwMakeContextCurrent(_glfwWindow); // create and bind framebuffer GLuint fbo; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); // create and bind texture GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, null); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); // render scene to framebuffer glBindFramebuffer(GL_FRAMEBUFFER, fbo); // render your scene here // read pixel data from framebuffer glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, imgslice.ptr); // flip image vertically for (size_t y = 0; y < height / 2; y++) { for (size_t x = 0; x < width; x++) { // swap rows swap(imgslice[y][x], imgslice[height - y - 1][x]); } } // unbind framebuffer and cleanup glBindFramebuffer(GL_FRAMEBUFFER, 0); glDeleteTextures(1, &texture); glDeleteFramebuffers(1, &fbo); return imgslice; } ``` And this is the code after required modifications: ```d auto plot2imslice() nogc nothrow { import mir.rc; Slice!(RCI!ubyte, 3LU, Contiguous) imgslice = rcslice!ubyte([height, width, 3], 0); glfwMakeContextCurrent(_glfwWindow); // create and bind framebuffer GLuint fbo; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); // create and bind texture GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, null); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); // render scene to framebuffer glBindFramebuffer(GL_FRAMEBUFFER, fbo); // render scene here render(); // read pixel data from framebuffer glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, imgslice.ptr); import mir.utility : swap; // flip image vertically to correct generated image foreach (y; 0..height / 2) { each!swap(imgslice[y], imgslice[height - y - 1]); } // unbind framebuffer and cleanup glBindFramebuffer(GL_FRAMEBUFFER, 0); glDeleteTextures(1, &texture); glDeleteFramebuffers(1, &fbo); return imgslice; } ``` This comment of chatGPT saved the day :) // render your scene here
Apr 14 2023