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.

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

2 Likes

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