ChatGP Model - GPT-4

I was playing around with ChatGPT last night. Model 4 writes Clarion code. I have not compiled the code to see that it functions. However, I thought it was remarkable that it can take some basic parameters and write out a function and, upon subsequent request, create a window structure that calls the function. And, in the conversation, tells you what it’s doing.

PROGRAM

INCLUDE('windows.inc')

TriangleWindow WINDOW('Triangle Solver'), AT(,,350,200), CENTER, FONT('Segoe UI', 10), GRAY
  PROMPT('Side A:', , , , , , , , , )
  ENTRY(@n10.2), AT(80,20), USE(?SideA)
  PROMPT('Side B:', , , , , , , , , )
  ENTRY(@n10.2), AT(80,50), USE(?SideB)
  PROMPT('Side C:', , , , , , , , , )
  ENTRY(@n10.2), AT(80,80), USE(?SideC)
  BUTTON('Solve'), AT(210,20,80,25), USE(?Solve)
  BUTTON('Exit'), AT(210,50,80,25), USE(?Exit)
  TEXT('Result:'), AT(20, 130, 40, 12)
  ENTRY(@s40), AT(60,130,200,20), USE(?Result)
END

TriangleSolve PROCEDURE(REAL a, REAL b, REAL c)
  REAL missingSide
CODE
  IF a = 0
    missingSide = SQRT(c * c - b * b)
  ELSIF b = 0
    missingSide = SQRT(c * c - a * a)
  ELSIF c = 0
    missingSide = SQRT(a * a + b * b)
  ELSE
    missingSide = 0
  END

  RETURN missingSide

CODE

  OPEN(TriangleWindow)

  ACCEPT
    CASE FIELD()
    OF ?Solve
      REAL a, b, c, result

      a = ?SideA{PROP:Text}
      b = ?SideB{PROP:Text}
      c = ?SideC{PROP:Text}

      result = TriangleSolve(a, b, c)

      ?Result{PROP:Text} = FORMAT(result, '###.00')
    OF ?Exit
      BREAK
    END
  END

Apparently GPT 3.5 produces code as well.

1 Like

While that code feels close, it’s wrong for a number of reasons.
It’s important to point these problems out to ChatGPT so that it can improve.
I have pointed out missing CODE directives in the past
and it looks like it’s getting that correct now.


NOTE: after posting the following, I took the liberty of reformatting your post to identify all of the code as CODE, as a result several of the indentation issues were solved.

You can mark code as CODE in a hub posting by selecting the code, and pressing the button that looks like —v
image

Note, on touch devices like phones, that button is tucked away in a sub-menu, select code, then press the GEAR button
image
then select Preformatted Text


I haven’t tried to compile this either, but I see the following issues:

a) there is no MAP near program
that means that SQRT won’t be found as it’s in BUILTINS.clw

b) there is no MAP / Prototype for TriangleSolve

c) The TriangleSolve PROCEDURE is in the wrong place
it needs to be after the accept loop code

d) REAL a,b,c,result is not clarion code at all
(see e below for some more details on declaring variables)
we also have
REAL missingSide which is backwards

e) a = ?SideA{PROP:Text} is wrong
prop text will return ‘@N10.2’ in that case
you could use a = CONTENTS(?SideA)
but it’s typical to declare A above the window structure
and have a USE(A) vs. a USE(?SideA)

f) there are indentation problems
especially as CW uses column 1 for labels

g) the picture of ‘###.00’ is wrong in the FORMAT call

h) ?Result{PROP:Text} = newvalue is wrong
you could use a CHANGE( ?Result, NewValue )
but again a USE variable and a DISPLAY are more typical

i) I don’t see a reason for INLCUDE(‘windows.inc’)
and most includes (without sections) would have a ,ONCE after them

j) the PROMPT s in the window window structure don’t have AT attributes

k) the windows ,AT attribute is odd ,AT(,350,200)
which looks like
XPOS is omitted
YPOS =350
WIDTH = 200
Height is omitted

l) there is an END for the CASE FIELD() but not for the ACCEPT

m) there is a TEXT control in the window structure
while that could technically be used
it’s not typical, and it appears like it’s being used a prompt

3 Likes

Thanks for the review and feedback on the code. I’ll share this with ChatGPT on the session.

Thanks Mark it invaluable.

I just asked 4.0 to generate code to loop thru a file and it wrote the complete program as you had flagged it for not doing.

Apparently, it learned from your instruction.

It now generates a complete program.
(Well, not sure what complete actually looks like, but here it is:)

PROGRAM
INCLUDE('windows.inc')
INCLUDE('debuger.inc')
MAP
  INCLUDE('windows.inc')
END
; Global data
GlobalData SECTION
  trackingFile       FILE, DRIVER('DOS'), NAME('tracking.txt')
    recordLine         CSTRING(256)
  END
END

; Main procedure
CODE
  OPEN(trackingFile)
  IF ERRORCODE()
    MESSAGE('Error opening the file: ' & FORMAT(ERRORCODE()))
    RETURN
  END

  LOOP
    NEXT(trackingFile)
    IF ERRORCODE()
      IF ERRORCODE() = 2 ; End of file
        BREAK
      ELSE
        MESSAGE('Error reading the file: ' & FORMAT(ERRORCODE()))
        CLOSE(trackingFile)
        RETURN
      END
    END
    ProcessRecord(recordLine)
  END

  CLOSE(trackingFile)
  RETURN
ProcessRecord PROCEDURE(STRING pRecord)
CODE
  ; Here you can process the record read from the file
  MESSAGE('Record: ' & pRecord)
END
1 Like

OK, again it looks close
but there are several details that need fixing / improvement

Issues:

a) no need for INCLUDE(‘windows.inc’)
or INCLUDE(‘debuger.inc’)

b) MAP
INCLUDE(‘windows.inc’)
END
is wrong, the content of windows.inc is not appropropriate for putting inside of MAP

c) when doing INCLUDE normally you’d add the ,ONCE attribute

d) they seem to think that ; introduces a comment vs. !

e) TrackingFile and RecordLine need are labels and need to be on the 1st column

f) RECORD & END are missing

g) most files have a prefix, but I don’t think one is required
unless you have a KEY

h) CODE is present, but it’s normally indented
I’d have to run a test, to see if it’s ok to have it in the 1st column

i) the message has FORMAT(ERRORCODE())
FORMAT needs 2 arguments
and in this case you don’t need format at all

j) I think there needs to be a SET(TrackingFile) before the NEXT(TrackingFile)
but it’s possible that it might work without it.

k) IF ERRORCODE() = 2 ; End of file
umm, well NoFileError EQUATE(2)
and again I think they think that a ; introduces a comment !

l) passing recordLine
I think you can pass recordLine this way
but normally you’d use a prefix before it (and this none)
you can write TrackingFile.RecordLine

m) ProcessRecord needs a prototype in the MAP

n) again CODE should be indented

o) there should NOT be an END here

p) lastly looking that the LOGIC
I find it interesting that when the errorcode() is not (supposedly) end of file
that there’s a MESSAGE followed by
Close(TrackingFile)
RETURN
vs. just doing a BREAK where the same two commands appear after the loop

1 Like

I’m sure there is a lot more improvement needed.
Wonder how long it will take for “them” (“It?”) to make the next round of changes.

Stev, what are trying to say?

https://twitter.com/bilawalsidhu/status/1639688267695112194

I’m not certain, but it seems to me that you can help it learn by asking it a question and then pointing out how to improve it’s answer.

1 Like

Kind of like a human intern…

:slight_smile:

When someone (gpt or a human) is asked to write some code for a given task

What do they do when they’re not proficient (or better) in the language, or not knowledgeable about the given task at hand

It’s common to look for examples and adapt them. Now if the example is in another language, then you also must translate too.

I think that’s a lot of what GPT is doing
There’s a fair number of mistakes in the resulting code. I think that’s in large part due to the rarity of CW and relatively small number of CW examples to draw from.

It would be interesting to look at GPTs responses to similar requests when using a mainstream language.

Sure I’m getting to 15 or so points with GPTs responses. I wonder how many points I’d get to with a human’s response when they take the challenge to hand code the response in NOTEPAD only.

By “Notepad” I mean no window formatter, no syntax highlighting, no code completion, no snippets, and certainly no compiler. Which is effectively the environment that GPT is using.

2 Likes