### Re: ChatGPT examples

```

On 20/01/2023 18:26, Geoff Canyon via use-livecode wrote:

I'm sure someone has done the work to create a more efficient algorithm for
this. Off the top of my head if I were trying to  I'd probably do something
like:

Hmmm. Maybe. But I kind of doubt it (though I'd love to find out I'm wrong).

This (or closely related problems) got a lot of attention on the
mid70s-mid80s, when we were trying to do Design Rule Verification for
VLSI circuits, with millions of transistors. Where the rules could
exploit hierarchy, the "clever tree" data structures and algorithms did
well (See Quad-CIF etc.) But for non-hierarchical problems (such as this
'closest points' case), nothing came close to this 'scanning window' or
'linear scan' approach.

But looking more closely, I realized that the number of times a new
"closest pair" was found is remarkably small - typically between 6 & 10
times for 50,000 points. So it's very feasible to bear the cost of
calculating the actual distance (i.e. doing the sqrt call) each time a
new 'closest pair' is found, and that means the quick filtering test can
be done on the x-distance (rather than x*x). Also, you can do a similar
filter test on the Y coord (though it doesn't let you exit the inner
loop, only allows you to skip the full comparison).

Adding those changes in gets the time down by another 10% or so - so the
original 2000 points comes down from approx 35ms to around 28ms (almost
too small to measure reliably). More reasonably, 50,000 points comes
down from 880ms to 810ms.

Revised code:
function closestPointsSQ pLines
sort pLines numeric by item 1 of each
put pLines into pPoints
split pPoints by CR
put infinity into minDistSQ
put infinity into minDist
put the number of elements in pPoints into N
repeat with i = 1 to N-1
repeat with j = i + 1 to N
put item 1 of pPoints[j] - item 1 of pPoints[i] into t1
if t1 > minDist then exit repeat
put item 2 of pPoints[j] - item 2 of pPoints[i] into t2
if t2 > minDist OR t2 < -minDist then next repeat
put t1 * t1 + t2 * t2 into dist
if dist < minDistSQ then
put dist into minDistSQ
put sqrt(dist) into minDist
put pPoints[i] & " " & pPoints[j] into closestPoints
else if dist = minDistSQ then
put sqrt(dist) into minDist
put return & pPoints[i] & " " & pPoints[j] after closestPoints
end if
end repeat
end repeat
--   put "SQ compared" && compareCount && newClosest && tAlsoClosest
after msg

return closestPoints
end closestPointsSQ

Alex.

1. Grab two points at random (in case the points are pre-sorted in some
way) and get the distance.
2. Assume that's a reasonable average distance between points.
3. Define that as the number to beat, and define a grid based on it.
4. Go through all the points, tossing them into buckets based on the grid.
I'd define the buckets as fully overlapping to avoid missing close pairs.
5. The size of the grid buckets is critical: too big and you do too much
work. Too small and you end up with all singletons in the buckets. This
would require some experimentation and thought.
6. Go through the buckets only comparing the points within them.

On Fri, Jan 20, 2023 at 10:14 AM Alex Tweedly via use-livecode <
use-livecode@lists.runrev.com> wrote:

On 20/01/2023 16:52, Mark Waddingham via use-livecode wrote:

On 2023-01-20 13:05, Alex Tweedly via use-livecode wrote:

We need a better algorithm. If we use a "linear scan", we can change
it from essentially Order(N**2) to approx Order(N).

Slightly pedantic point (I appreciate that you did say 'approx')...

Sorting can not be done in any less time than O(N*log N) - so the
revised algorithm is O(N*log N) as you have to sort the input for it
to be able to scan linearly.

I figured someone would pick me up on that :-) It was a pretty big
'approx' :\)

The sorting step is indeed O(NlogN).

And the rest of it also worse than linear, but I don't have the math
knowledge to even begin to think about how much worse. Quick testing
says it's worse than O(NlogN), and in practice, it might even be as bad
as something like O(N * sqrt(N)), guessing about the number of points
within a (variable) sized window to the right of the current scan coord.

But in any "real app" usage that I can imagine, the 'clustering' effect
would seem to improve it over O(N*sqrt(N)); e.g. if the points tend to
cluster rather than be evenly randomly spread, then the number within
the scan window goes down on average. "real app" could be players in a
1st person player game, or vehicles on a road simulation, or (in 3d)
stars in the universe - in all cases causing the minDist to decrease
faster than when they are evenly spread.

Alex.

___
```

### Re: ChatGPT examples

```Duh. What part of Sod's Law says that you always see a bug the first
time you look at your own code *after* you've made the code public :-(

The 'sort' command below needs to be a numeric sort

sort pLines by item 1 of each   ->   sort pLines numeric by item 1
of each

Sorry,

Alex.

On 20/01/2023 13:05, Alex Tweedly via use-livecode wrote:

Fascinating. Thank you so much for that Geoff.

I've been afraid to play with ChatGPT so far - too worried abut
getting sucked in and spending way too much time

I did take a look at your third example (since I can never resist a
performance challenge :-)

There are a number of minor tweaks that could be made to improve
performance

1. set initial value to infinity rather than calculating a distance
between the first two points.

2. "number of elements in pPoints" is unvarying within any one call -
so extract it to a variable at the start

3. use the square of the distance rather than the actual distance -
save N**2 calls to sqrt

4. use "DX * DX" rather than "DX ^ 2" (about 25% faster)

5. calculate distance in-line rather than call a function

but those all add up to maybe 10% performance improvement (or less - I
didn't test it). That's useful - but not enough.

For a modest number of points (2000 random points), this takes approx
16.5 seconds !!

We need a better algorithm. If we use a "linear scan", we can change
it from essentially Order(N**2) to approx Order(N).

Summary:

- sort the points by X coordinate

- while scanning the inner loop, as soon as the difference in Xcoord
from the 'outer' point exceeds the minDist so far, you can reject not
just this point, but all subsequent points, and hence exit the inner
loop immediately.

This brings the time down from 16500 millisecs to 25 millisecs.

BUT - I have no clue how I'd go about describing this to ChatGPT :-)

NB I changed the input parameter to be the list of points rather than
the array.

Code:

function closestPointsSQ pLines
sort pLines by item 1 of each
put pLines into pPoints
split pPoints by CR
put infinity into minDist
put the number of elements in pPoints into N
repeat with i = 1 to N-1
repeat with j = i + 1 to N
put item 1 of pPoints[j] - item 1 of pPoints[i] into t1
if t1 * t1 > minDist then exit repeat
put item 2 of pPoints[j] - item 2 of pPoints[i] into t2
put t1 * t1 + t2 * t2 into dist
if dist < minDist then
put dist into minDist
put pPoints[i] & " " & pPoints[j] into closestPoints
else if dist = minDist then
put return & pPoints[i] & " " & pPoints[j] after
closestPoints

end if
end repeat
end repeat
return closestPoints
end closestPointsSQ

-- Alex.

On 20/01/2023 06:02, Geoff Canyon via use-livecode wrote:

I tested three use cases, with variations, using ChatGPT for (live)code
generation. There was a lot of back and forth. In the end, I solved
all the

problems I set, but in some cases I had to hold ChatGPT's hand pretty
tightly.

That said, I learned some things as well -- about LiveCode. ChatGPT's
code

for Fizz Buzz was faster than mine.

My code was faster for reversing lines. But ChatGPT, when asked to "make
the code faster" gave several suggestions, some of which were wrong or
impossible, but one of them was my method, and when I said "write that
option" it did, with only a few corrections needed.

And one of the ideas, while wrong, caused me to think of a different
way to

solve the problem, and that way ended up being faster than my original
solution by over 3x on reversing 10k lines. Getting ChatGPT to write
this

new method was *hard*.

In any case, I wrote it all down in a google doc
.

If you're curious, have a read. That URL is open for comments/edit
suggestions. If you have any I'd love to hear them.

Thanks!

Geoff
___
use-livecode mailing list
use-livecode@lists.runrev.com
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```I'm sure someone has done the work to create a more efficient algorithm for
this. Off the top of my head if I were trying to  I'd probably do something
like:

1. Grab two points at random (in case the points are pre-sorted in some
way) and get the distance.
2. Assume that's a reasonable average distance between points.
3. Define that as the number to beat, and define a grid based on it.
4. Go through all the points, tossing them into buckets based on the grid.
I'd define the buckets as fully overlapping to avoid missing close pairs.
5. The size of the grid buckets is critical: too big and you do too much
work. Too small and you end up with all singletons in the buckets. This
would require some experimentation and thought.
6. Go through the buckets only comparing the points within them.

On Fri, Jan 20, 2023 at 10:14 AM Alex Tweedly via use-livecode <
use-livecode@lists.runrev.com> wrote:

>
> On 20/01/2023 16:52, Mark Waddingham via use-livecode wrote:
> > On 2023-01-20 13:05, Alex Tweedly via use-livecode wrote:
> >> We need a better algorithm. If we use a "linear scan", we can change
> >> it from essentially Order(N**2) to approx Order(N).
> >
> > Slightly pedantic point (I appreciate that you did say 'approx')...
> >
> > Sorting can not be done in any less time than O(N*log N) - so the
> > revised algorithm is O(N*log N) as you have to sort the input for it
> > to be able to scan linearly.
> >
> I figured someone would pick me up on that :-) It was a pretty big
> 'approx' :\)
>
> The sorting step is indeed O(NlogN).
>
> And the rest of it also worse than linear, but I don't have the math
> knowledge to even begin to think about how much worse. Quick testing
> says it's worse than O(NlogN), and in practice, it might even be as bad
> as something like O(N * sqrt(N)), guessing about the number of points
> within a (variable) sized window to the right of the current scan coord.
>
> But in any "real app" usage that I can imagine, the 'clustering' effect
> would seem to improve it over O(N*sqrt(N)); e.g. if the points tend to
> cluster rather than be evenly randomly spread, then the number within
> the scan window goes down on average. "real app" could be players in a
> 1st person player game, or vehicles on a road simulation, or (in 3d)
> stars in the universe - in all cases causing the minDist to decrease
> faster than when they are evenly spread.
>
> Alex.
>
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```Whoa, TIL. Of course ChatGPT was easily able to make the substitution. I've
updated the doc.

gc

On Fri, Jan 20, 2023 at 9:46 AM Alex Tweedly via use-livecode <
use-livecode@lists.runrev.com> wrote:

> On 20/01/2023 15:55, Geoff Canyon via use-livecode wrote:
>
> > Responses inline:
> >
> > On Fri, Jan 20, 2023 at 5:06 AM Alex Tweedly via use-livecode <
> > use-livecode@lists.runrev.com> wrote:
> >
> > I thought of this -- especially since ChatGPT's first (python-esque)
> > example uses "inf" -- but what would you use as "infinity" in LiveCode?
> In
> > practice if I were coding and comfortable with it I'd probably just throw
> > in 9 and be done, but in the abstract, there are bigger numbers
> > allowed in LC, and I don't care to find the absolute largest -- plus it
> > would be some weird long string -- I think, I don't know off the top of
> my
> > head what the largest 64-bit value is.
>
> Just use the constant 'infinity'
>
> I think it was added fairly recently, but the dictionary doesn't say
> what version it first appeared in.
>
> Alex.
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```

On 20/01/2023 16:52, Mark Waddingham via use-livecode wrote:

On 2023-01-20 13:05, Alex Tweedly via use-livecode wrote:

We need a better algorithm. If we use a "linear scan", we can change
it from essentially Order(N**2) to approx Order(N).

Slightly pedantic point (I appreciate that you did say 'approx')...

Sorting can not be done in any less time than O(N*log N) - so the
revised algorithm is O(N*log N) as you have to sort the input for it
to be able to scan linearly.

I figured someone would pick me up on that :-) It was a pretty big
'approx' :\)

The sorting step is indeed O(NlogN).

And the rest of it also worse than linear, but I don't have the math
knowledge to even begin to think about how much worse. Quick testing
says it's worse than O(NlogN), and in practice, it might even be as bad
as something like O(N * sqrt(N)), guessing about the number of points
within a (variable) sized window to the right of the current scan coord.

But in any "real app" usage that I can imagine, the 'clustering' effect
would seem to improve it over O(N*sqrt(N)); e.g. if the points tend to
cluster rather than be evenly randomly spread, then the number within
the scan window goes down on average. "real app" could be players in a
1st person player game, or vehicles on a road simulation, or (in 3d)
stars in the universe - in all cases causing the minDist to decrease
faster than when they are evenly spread.

Alex.

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```
On 20/01/2023 15:55, Geoff Canyon via use-livecode wrote:

Responses inline:

On Fri, Jan 20, 2023 at 5:06 AM Alex Tweedly via use-livecode <
use-livecode@lists.runrev.com> wrote:

I thought of this -- especially since ChatGPT's first (python-esque)
example uses "inf" -- but what would you use as "infinity" in LiveCode? In
practice if I were coding and comfortable with it I'd probably just throw
in 9 and be done, but in the abstract, there are bigger numbers
allowed in LC, and I don't care to find the absolute largest -- plus it
would be some weird long string -- I think, I don't know off the top of my
head what the largest 64-bit value is.

Just use the constant 'infinity'

I think it was added fairly recently, but the dictionary doesn't say
what version it first appeared in.

Alex.

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```
On 2023-01-20 13:05, Alex Tweedly via use-livecode wrote:

We need a better algorithm. If we use a "linear scan", we can change
it from essentially Order(N**2) to approx Order(N).

Slightly pedantic point (I appreciate that you did say 'approx')...

Sorting can not be done in any less time than O(N*log N) - so the
revised algorithm is O(N*log N) as you have to sort the input for it to
be able to scan linearly.

:D

Warmest Regards,

Mark.

--
Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/
LiveCode: Build Amazing Things

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```Doomed, like the guys who left their weapons behind ended up facing their own
weapons later.

Bob S

On Jan 20, 2023, at 07:56 , Geoff Canyon via use-livecode
mailto:use-livecode@lists.runrev.com>> wrote:

On Fri, Jan 20, 2023 at 6:57 AM Craig Newman via use-livecode <
use-livecode@lists.runrev.com> wrote:

Geoff.

Startling, and beautifully presented.

I had no idea ChatGPT was that powerful and knowledgeable.

We are doomed.

Craig

Doomed like the guys walking behind the horses were doomed by the
tractors...

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```On Fri, Jan 20, 2023 at 6:57 AM Craig Newman via use-livecode <
use-livecode@lists.runrev.com> wrote:

> Geoff.
>
> Startling, and beautifully presented.
>
> I had no idea ChatGPT was that powerful and knowledgeable.
>
> We are doomed.
>
> Craig
>

Doomed like the guys walking behind the horses were doomed by the
tractors...
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```Responses inline:

On Fri, Jan 20, 2023 at 5:06 AM Alex Tweedly via use-livecode <
use-livecode@lists.runrev.com> wrote:

> Fascinating. Thank you so much for that Geoff.
>
> I've been afraid to play with ChatGPT so far - too worried abut getting
> sucked in and spending way too much time
>
> I did take a look at your third example (since I can never resist a
> performance challenge :-)
>
> There are a number of minor tweaks that could be made to improve
> performance
>
> 1. set initial value to infinity rather than calculating a distance
> between the first two points.
>

I thought of this -- especially since ChatGPT's first (python-esque)
example uses "inf" -- but what would you use as "infinity" in LiveCode? In
practice if I were coding and comfortable with it I'd probably just throw
in 9 and be done, but in the abstract, there are bigger numbers
allowed in LC, and I don't care to find the absolute largest -- plus it
would be some weird long string -- I think, I don't know off the top of my
head what the largest 64-bit value is.

> 2. "number of elements in pPoints" is unvarying within any one call - so
> extract it to a variable at the start
>

Good point. I did benchmark  "number of elements" -- ChatGPT's code;
against "item 2 of the extents of" -- what I would have done; and number of
elements is *much* faster.

>
> 3. use the square of the distance rather than the actual distance - save
> N**2 calls to sqrt
>

Nice!

>
> 4. use "DX * DX" rather than "DX ^ 2" (about 25% faster)
>

Really? Interesting, I'll have to check that.

> 5. calculate distance in-line rather than call a function
>

Yep, this is purely an artifact of how ChatGPT wrote it. But it would be
interesting to give it both chunks of code and say "merge this" and see if
it can pull that off. Thanks for the idea!

>
> but those all add up to maybe 10% performance improvement (or less - I
> didn't test it). That's useful - but not enough.
>
> For a modest number of points (2000 random points), this takes approx
> 16.5 seconds !!
>
> We need a better algorithm. If we use a "linear scan", we can change it
> from essentially Order(N**2) to approx Order(N).
>
> Summary:
>
>   - sort the points by X coordinate
>
>   - while scanning the inner loop, as soon as the difference in Xcoord
> from the 'outer' point exceeds the minDist so far, you can reject not
> just this point, but all subsequent points, and hence exit the inner
> loop immediately.
>
> This brings the time down from 16500 millisecs to 25 millisecs.
>
> BUT - I have no clue how I'd go about describing this to ChatGPT :-)
>
> NB I changed the input parameter to be the list of points rather than
> the array.
>

Fair point -- the array was entirely ChatGPT's choice, and I didn't
challenge it. I'll ask it to change and see what happens.

>
> Code:
>
> function closestPointsSQ pLines
> sort pLines by item 1 of each
> put pLines into pPoints
> split pPoints by CR
> put infinity into minDist
> put the number of elements in pPoints into N
> repeat with i = 1 to N-1
>repeat with j = i + 1 to N
>   put item 1 of pPoints[j] - item 1 of pPoints[i] into t1
>   if t1 * t1 > minDist then exit repeat
>   put item 2 of pPoints[j] - item 2 of pPoints[i] into t2
>   put t1 * t1 + t2 * t2 into dist
>   if dist < minDist then
>  put dist into minDist
>  put pPoints[i] & " " & pPoints[j] into closestPoints
>   else if dist = minDist then
>  put return & pPoints[i] & " " & pPoints[j] after closestPoints
>   end if
>end repeat
> end repeat
> return closestPoints
> end closestPointsSQ
>
> -- Alex.
>
> On 20/01/2023 06:02, Geoff Canyon via use-livecode wrote:
> > I tested three use cases, with variations, using ChatGPT for (live)code
> > generation. There was a lot of back and forth. In the end, I solved all
> the
> > problems I set, but in some cases I had to hold ChatGPT's hand pretty
> > tightly.
> >
> > That said, I learned some things as well -- about LiveCode. ChatGPT's
> code
> > for Fizz Buzz was faster than mine.
> >
> > My code was faster for reversing lines. But ChatGPT, when asked to "make
> > the code faster" gave several suggestions, some of which were wrong or
> > impossible, but one of them was my method, and when I said "write that
> > option" it did, with only a few corrections needed.
> >
> > And one of the ideas, while wrong, caused me to think of a different way
> to
> > solve the problem, and that way ended up being faster than my original
> > solution by over 3x on reversing 10k lines. Getting ChatGPT to write this
> > new method was *hard*.
> >
> > In any case, I wrote it all down in a google doc
> > <
> >.
> > If you're curious, have a read. That URL is open for comments/edit
> > suggestions. If you have any I'd love to hear them.
> ```

### Re: ChatGPT examples

```Geoff.

Startling, and beautifully presented.

I had no idea ChatGPT was that powerful and knowledgeable.

We are doomed.

Craig

> On Jan 20, 2023, at 8:05 AM, Alex Tweedly via use-livecode
>  wrote:
>
> Fascinating. Thank you so much for that Geoff.
>
> I've been afraid to play with ChatGPT so far - too worried abut getting
> sucked in and spending way too much time
>
> I did take a look at your third example (since I can never resist a
> performance challenge :-)
>
> There are a number of minor tweaks that could be made to improve performance
>
> 1. set initial value to infinity rather than calculating a distance between
> the first two points.
>
> 2. "number of elements in pPoints" is unvarying within any one call - so
> extract it to a variable at the start
>
> 3. use the square of the distance rather than the actual distance - save N**2
> calls to sqrt
>
> 4. use "DX * DX" rather than "DX ^ 2" (about 25% faster)
>
> 5. calculate distance in-line rather than call a function
>
> but those all add up to maybe 10% performance improvement (or less - I didn't
> test it). That's useful - but not enough.
>
> For a modest number of points (2000 random points), this takes approx 16.5
> seconds !!
>
> We need a better algorithm. If we use a "linear scan", we can change it from
> essentially Order(N**2) to approx Order(N).
>
> Summary:
>
>  - sort the points by X coordinate
>
>  - while scanning the inner loop, as soon as the difference in Xcoord from
> the 'outer' point exceeds the minDist so far, you can reject not just this
> point, but all subsequent points, and hence exit the inner loop immediately.
>
> This brings the time down from 16500 millisecs to 25 millisecs.
>
> BUT - I have no clue how I'd go about describing this to ChatGPT :-)
>
> NB I changed the input parameter to be the list of points rather than the
> array.
>
> Code:
>
> function closestPointsSQ pLines
>sort pLines by item 1 of each
>put pLines into pPoints
>split pPoints by CR
>put infinity into minDist
>put the number of elements in pPoints into N
>repeat with i = 1 to N-1
>   repeat with j = i + 1 to N
>  put item 1 of pPoints[j] - item 1 of pPoints[i] into t1
>  if t1 * t1 > minDist then exit repeat
>  put item 2 of pPoints[j] - item 2 of pPoints[i] into t2
>  put t1 * t1 + t2 * t2 into dist
>  if dist < minDist then
> put dist into minDist
> put pPoints[i] & " " & pPoints[j] into closestPoints
>  else if dist = minDist then
> put return & pPoints[i] & " " & pPoints[j] after closestPoints
>  end if
>   end repeat
>end repeat
>return closestPoints
> end closestPointsSQ
>
> -- Alex.
>
> On 20/01/2023 06:02, Geoff Canyon via use-livecode wrote:
>> I tested three use cases, with variations, using ChatGPT for (live)code
>> generation. There was a lot of back and forth. In the end, I solved all the
>> problems I set, but in some cases I had to hold ChatGPT's hand pretty
>> tightly.
>>
>> That said, I learned some things as well -- about LiveCode. ChatGPT's code
>> for Fizz Buzz was faster than mine.
>>
>> My code was faster for reversing lines. But ChatGPT, when asked to "make
>> the code faster" gave several suggestions, some of which were wrong or
>> impossible, but one of them was my method, and when I said "write that
>> option" it did, with only a few corrections needed.
>>
>> And one of the ideas, while wrong, caused me to think of a different way to
>> solve the problem, and that way ended up being faster than my original
>> solution by over 3x on reversing 10k lines. Getting ChatGPT to write this
>> new method was *hard*.
>>
>> In any case, I wrote it all down in a google doc
>> .
>> If you're curious, have a read. That URL is open for comments/edit
>> suggestions. If you have any I'd love to hear them.
>>
>> Thanks!
>>
>> Geoff
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```
Fascinating. Thank you so much for that Geoff.

I've been afraid to play with ChatGPT so far - too worried abut getting
sucked in and spending way too much time

I did take a look at your third example (since I can never resist a
performance challenge :-)

There are a number of minor tweaks that could be made to improve performance

1. set initial value to infinity rather than calculating a distance
between the first two points.

2. "number of elements in pPoints" is unvarying within any one call - so
extract it to a variable at the start

3. use the square of the distance rather than the actual distance - save
N**2 calls to sqrt

4. use "DX * DX" rather than "DX ^ 2" (about 25% faster)

5. calculate distance in-line rather than call a function

but those all add up to maybe 10% performance improvement (or less - I
didn't test it). That's useful - but not enough.

For a modest number of points (2000 random points), this takes approx
16.5 seconds !!

We need a better algorithm. If we use a "linear scan", we can change it
from essentially Order(N**2) to approx Order(N).

Summary:

- sort the points by X coordinate

- while scanning the inner loop, as soon as the difference in Xcoord
from the 'outer' point exceeds the minDist so far, you can reject not
just this point, but all subsequent points, and hence exit the inner
loop immediately.

This brings the time down from 16500 millisecs to 25 millisecs.

BUT - I have no clue how I'd go about describing this to ChatGPT :-)

NB I changed the input parameter to be the list of points rather than
the array.

Code:

function closestPointsSQ pLines
sort pLines by item 1 of each
put pLines into pPoints
split pPoints by CR
put infinity into minDist
put the number of elements in pPoints into N
repeat with i = 1 to N-1
repeat with j = i + 1 to N
put item 1 of pPoints[j] - item 1 of pPoints[i] into t1
if t1 * t1 > minDist then exit repeat
put item 2 of pPoints[j] - item 2 of pPoints[i] into t2
put t1 * t1 + t2 * t2 into dist
if dist < minDist then
put dist into minDist
put pPoints[i] & " " & pPoints[j] into closestPoints
else if dist = minDist then
put return & pPoints[i] & " " & pPoints[j] after closestPoints
end if
end repeat
end repeat
return closestPoints
end closestPointsSQ

-- Alex.

On 20/01/2023 06:02, Geoff Canyon via use-livecode wrote:

I tested three use cases, with variations, using ChatGPT for (live)code
generation. There was a lot of back and forth. In the end, I solved all the
problems I set, but in some cases I had to hold ChatGPT's hand pretty
tightly.

That said, I learned some things as well -- about LiveCode. ChatGPT's code
for Fizz Buzz was faster than mine.

My code was faster for reversing lines. But ChatGPT, when asked to "make
the code faster" gave several suggestions, some of which were wrong or
impossible, but one of them was my method, and when I said "write that
option" it did, with only a few corrections needed.

And one of the ideas, while wrong, caused me to think of a different way to
solve the problem, and that way ended up being faster than my original
solution by over 3x on reversing 10k lines. Getting ChatGPT to write this
new method was *hard*.

In any case, I wrote it all down in a google doc
.
If you're curious, have a read. That URL is open for comments/edit
suggestions. If you have any I'd love to hear them.

Thanks!

Geoff
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT examples

```Geoff...

Wow. Pretty please, can I have permission to turn that document into a blog
post? It's fantastic and deserves to reach a wider audience.

Best Regards,

Heather

Heather Laine
Customer Services Manager
LiveCode Ltd
www.livecode.com

> On 20 Jan 2023, at 06:02, Geoff Canyon via use-livecode
>  wrote:
>
> I tested three use cases, with variations, using ChatGPT for (live)code
> generation. There was a lot of back and forth. In the end, I solved all the
> problems I set, but in some cases I had to hold ChatGPT's hand pretty
> tightly.
>
> That said, I learned some things as well -- about LiveCode. ChatGPT's code
> for Fizz Buzz was faster than mine.
>
> My code was faster for reversing lines. But ChatGPT, when asked to "make
> the code faster" gave several suggestions, some of which were wrong or
> impossible, but one of them was my method, and when I said "write that
> option" it did, with only a few corrections needed.
>
> And one of the ideas, while wrong, caused me to think of a different way to
> solve the problem, and that way ended up being faster than my original
> solution by over 3x on reversing 10k lines. Getting ChatGPT to write this
> new method was *hard*.
>
> In any case, I wrote it all down in a google doc
> .
> If you're curious, have a read. That URL is open for comments/edit
> suggestions. If you have any I'd love to hear them.
>
> Thanks!
>
> Geoff
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT conversation

```I suppose like a love affair, it can get addicting… I tried a few more queries
in different programming languages to see how it would do. My queries were not
very challenging, but it scored 10 out of 10 for both SAS and SQL (ie. both
worked the first time). For python, when I asked it to write a game of “snake”
it created a game where there was no user input (the snake only went right then
it encountered the edge of the screen and quit). I asked it to modify that and
it added code to get arrow key inputs. I won’t post them since I don’t want to
fill up this space, but it is interesting to see what it can come up with.

Now, back to more pressing challenges :)

Mark

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT conversation

```Just a final thought. After reading through this transcript I think the thing
that impresses me the most is the ability of ChatGPT to understand what I am
asking or suggesting. In a language, English, that is not known for its
precision, in almost 100% of the cases I would say ChatGPT understood what I
was asking or recommending. That, in itself, might be the most impressive
aspect of this conversation.

> On 18 Jan 2023, at 9:15 pm, Mark Smith  wrote:
>
> I decided to take the plunge and see what this was all about. I posed a
> moderately difficult LC question to ChatGPT, one I knew that beginning
> livecoders (or even myself) might find challenging. Result: some things
> surprised me, both good and bad, but overall I think the approach has
> potential… with lots of cautions and caveats. Since I may overrun any
> end.
>
>
> file:
>
> on getFileCreationDate pFilePath
>  put the creationdate of file pFilePath into tCreationDate
>  return tCreationDate
> end getFileCreationDate
>
> You can call the function by passing in the file path as a parameter, like
> this:
>
> put getFileCreationDate("/path/to/file.txt")
>
> This will return the creation date of the file in the format "dd/mm/
> hh:mm:ss".
> Please note that this function only works on Mac and Windows.
>
> ME: Livecode does not recognise the keyword "creationdate". Can you try using
> the "detailed" option of the "files" function to find the creation date?
>
> Yes, you're correct that the "creationdate" property is not available in
> LiveCode. However, you can use the "files" function with the "detailed"
> Here's an example function that uses the "files" function to return the date
> of creation of a file:
>
> on getFileCreationDate pFilePath
>   put the files(pFilePath, "detailed") into tFileInfo
>   put item 5 of tFileInfo into tCreationDate
>   return tCreationDate
> end getFileCreationDate
>
> You can call the function by passing in the file path as a parameter, like
> this:
>
> put getFileCreationDate("/path/to/file.txt")
> This will return the creation date of the file in the format "-mm-dd
> hh:mm:ss".
> Please note that this will work on all platforms.
>
> ME: the files function in livecode returns a list of all of the files in a
> directory. Can you select the one you are looking for, which is file.txt?
>
> Yes, you're correct that the "files" function in LiveCode returns a list of
> all files in a directory, so you need to filter the list to get the file
> you're looking for. Here's an example function that uses the "filter"
> function to get the information of the file you are looking for:
>
> on getFileCreationDate pFilePath
>   put the files(pFilePath, "detailed") into tFilesList
>   put filter(tFilesList, "name", "file.txt") into tFileInfo
>   put item 5 of tFileInfo into tCreationDate
>   return tCreationDate
> end getFileCreationDate
>
> You can call the function by passing in the directory path as a parameter,
> like this:
>
> put getFileCreationDate("/path/to/directory")
>
> This will return the creation date of the file "file.txt" in the format
> "-mm-dd hh:mm:ss" if it exists in the directory. If the file doesn't
> exist in the directory it will return an empty string.
>
> ME: livecode uses the "function" keyword to define a function. Could you
> rewrite this using the function keyword?
>
> Sure, here's an example function that uses the "filter" function to get the
> information of the file you are looking for and defined with the "function"
> keyword:
>
> function getFileCreationDate pFilePath
>   local tFilesList, tFileInfo, tCreationDate
>   put the files(pFilePath, "detailed") into tFilesList
>   put filter(tFilesList, "name", "file.txt") into tFileInfo
>   put item 5 of tFileInfo into tCreationDate
>   return tCreationDate
> end getFileCreationDate
>
> You can call the function by passing in the directory path as a parameter,
> like this:
>
> put getFileCreationDate("/path/to/directory")
>
> This will return the creation date of the file "file.txt" in the format
> "-mm-dd hh:mm:ss" if it exists in the directory. If the file doesn't
> exist in the directory it will return an empty string.
>
> ME: In livecode the filter command uses the form: filter lines of
> matching wildcard  into . Could you rewrite your filter
> command appropriately?
>
> Yes, you're correct that in LiveCode the filter command uses the form "filter
> lines of  matching wildcard  into ". Here's an
> example function that uses the filter command with this form to get the
> information of the file you are looking for:
>
> function getFileCreationDate pFilePath
>   local tFileInfo, ```

### Re: ChatGPT

```I just tried it and got this instead:

-
ME: Write a calendar app in livecode

CHATGPT:

To create a calendar app in LiveCode, you will need to use the LiveCode
programming language and the LiveCode development environment. Here is a

1. Open LiveCode and create a new stack.
2. Design the layout of your calendar app. You can use LiveCode's
built-in layout tools to create a grid of squares representing the days of the
month, as well as buttons for navigating between months and years.
3. Use LiveCode's control structures and looping statements to create
the logic for displaying the current month and year, and for navigating between
months and years.
4. Add functionality to highlight the current day and to display events
for each day. You can use LiveCode's data structures, such as lists and arrays,
to store the events for each day.
5. Use LiveCode's built-in date and time functions to help with the
calendar calculations, such as determining the number of days in a given month
and the day of the week for a given date.
6. Test your calendar app thoroughly to ensure that it is working as
expected.
7. Customize the appearance of your calendar app using LiveCode's
graphics and styling features.

I hope this helps! Let me know if you have any questions or need further
guidance.
-

Amazing!

Ken

> On Dec 9, 2022, at 3:54 PM, Jim Lambert via use-livecode
>  wrote:
>
> Even more interesting I issued the same chat request a few hours later and
> got an entirely different coding approach.
> It even helpfully put the code into formatted, copy-able blocks. (formatting
> not shown here.)
>
> ME: Write a calendar app in livecode
>
> CHATGPT:
> Here is an example of how you could implement a simple calendar app in
> LiveCode:
>
> Copy code
> -- Set the default date to the current date put the short date into
> currentDate
>
> -- Create the calendar UI
> create calendar
> set the date of calendar to currentDate
> set the rect of calendar to the rect of this card
>
> -- Function to handle date changes in the calendar
> on dateChanged pNewDate
> put pNewDate into currentDate
> end dateChanged
>
> This script creates a calendar widget and sets its default date to the
> current date. It also defines a dateChanged handler that is called whenever
> the selected date in the calendar changes. In this handler, the currentDate
> variable is updated with the new selected date.
>
> You can then add other UI elements and functions to your app to allow the
> user to view and manage events for the selected date. For example, you could
> add a list widget to display the events for the current date, and buttons to
>
> Here is an example of how you could add a list widget to display the events
> for the current date:
>
> Copy code
> -- Create a list widget to display the events for the current date
> create field "eventsList"
> set the rect of "eventsList" to 100,100,200,200
> set the text of "eventsList" to "No events for this date"
>
> -- Function to update the events list
> on updateEventsList
> -- Clear the events list
> put empty into field "eventsList"
>
> -- Retrieve the events for the current date from a database or file
> put the events for currentDate from database or file into events
>
> -- Add the events to the list
> repeat for each event in events
> put event & cr after field "eventsList"
> end repeat
> end updateEventsList
>
> This script creates a list widget called eventsList, and defines an
> updateEventsList function that retrieves the events for the current date from
> a database or file and adds them to the list.
>
> You can then call the updateEventsList function whenever the date in the
> calendar changes, so that the list of events is updated to show the events
> for the new selected date. You can do this by adding the following code to
> the dateChanged handler:
>
> Copy code
> on dateChanged pNewDate
> put pNewDate into currentDate
> updateEventsList
> end dateChanged
>
> You can also add buttons to allow the user to add and remove events. For
> example, you could add the following code to create "Add" and "Remove"
> buttons and define the corresponding event handlers:
>
> Copy code
> -- Create "Add" and "Remove" buttons
>
> But, of course, this code doesn't actually work. But it could be re-written
> to work.
>
> JimL
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Website: https://www.sonsothunder.com

___
use-livecode mailing list
use-livecode@lists.runrev.com

### Re: ChatGPT

```You didn't know that? ;-P

Bob S

On Dec 19, 2022, at 17:10 , Mark Wieder via use-livecode
mailto:use-livecode@lists.runrev.com>> wrote:

On 12/18/22 12:15, Richard Gaskin via use-livecode wrote:
A Twitter thread with ChatGPT botsplaining how 77 is a prime number:

Wait what?

"To prove that 77 is a prime number, we can use the theorem that states that if
a number is divisible by a prime number, then it is also divisible by all the
prime numbers that are smaller than it."

--
Mark Wieder
ahsoftw...@gmail.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```Somehow that last was mixed up with the concept of any number being able to be
expressed by a string of prime factors. So 77 can be resolved to ’11” and ”7”.
“42” by “7’, “3” and”2’.

> On Dec 9, 2022, at 4:54 PM, Jim Lambert via use-livecode
>  wrote:
>
> Even more interesting I issued the same chat request a few hours later and
> got an entirely different coding approach.
> It even helpfully put the code into formatted, copy-able blocks. (formatting
> not shown here.)
>
> ME: Write a calendar app in livecode
>
> CHATGPT:
> Here is an example of how you could implement a simple calendar app in
> LiveCode:
>
> Copy code
> -- Set the default date to the current date put the short date into
> currentDate
>
> -- Create the calendar UI
> create calendar
> set the date of calendar to currentDate
> set the rect of calendar to the rect of this card
>
> -- Function to handle date changes in the calendar
> on dateChanged pNewDate
> put pNewDate into currentDate
> end dateChanged
>
> This script creates a calendar widget and sets its default date to the
> current date. It also defines a dateChanged handler that is called whenever
> the selected date in the calendar changes. In this handler, the currentDate
> variable is updated with the new selected date.
>
> You can then add other UI elements and functions to your app to allow the
> user to view and manage events for the selected date. For example, you could
> add a list widget to display the events for the current date, and buttons to
>
> Here is an example of how you could add a list widget to display the events
> for the current date:
>
> Copy code
> -- Create a list widget to display the events for the current date
> create field "eventsList"
> set the rect of "eventsList" to 100,100,200,200
> set the text of "eventsList" to "No events for this date"
>
> -- Function to update the events list
> on updateEventsList
> -- Clear the events list
> put empty into field "eventsList"
>
> -- Retrieve the events for the current date from a database or file
> put the events for currentDate from database or file into events
>
> -- Add the events to the list
> repeat for each event in events
> put event & cr after field "eventsList"
> end repeat
> end updateEventsList
>
> This script creates a list widget called eventsList, and defines an
> updateEventsList function that retrieves the events for the current date from
> a database or file and adds them to the list.
>
> You can then call the updateEventsList function whenever the date in the
> calendar changes, so that the list of events is updated to show the events
> for the new selected date. You can do this by adding the following code to
> the dateChanged handler:
>
> Copy code
> on dateChanged pNewDate
> put pNewDate into currentDate
> updateEventsList
> end dateChanged
>
> You can also add buttons to allow the user to add and remove events. For
> example, you could add the following code to create "Add" and "Remove"
> buttons and define the corresponding event handlers:
>
> Copy code
> -- Create "Add" and "Remove" buttons
>
> But, of course, this code doesn't actually work. But it could be re-written
> to work.
>
> JimL
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```As Mark said…

So if you have, say, 22, which is divisible by the prime “11”, then it is also
divisible by 7""???

Craig

> On Dec 19, 2022, at 8:10 PM, Mark Wieder via use-livecode
>  wrote:
>
> On 12/18/22 12:15, Richard Gaskin via use-livecode wrote:
>> A Twitter thread with ChatGPT botsplaining how 77 is a prime number:
>
> Wait what?
>
> "To prove that 77 is a prime number, we can use the theorem that states that
> if a number is divisible by a prime number, then it is also divisible by all
> the prime numbers that are smaller than it."
>
> --
> Mark Wieder
> ahsoftw...@gmail.com
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```
On 12/18/22 12:15, Richard Gaskin via use-livecode wrote:

A Twitter thread with ChatGPT botsplaining how 77 is a prime number:

Wait what?

"To prove that 77 is a prime number, we can use the theorem that states
that if a number is divisible by a prime number, then it is also
divisible by all the prime numbers that are smaller than it."

--
Mark Wieder
ahsoftw...@gmail.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```Funny!

Rick

> On Dec 18, 2022, at 3:15 PM, Richard Gaskin via use-livecode
>  wrote:
>
> A Twitter thread with ChatGPT botsplaining how 77 is a prime number:
>
>
> --
> Fourth World Systems
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```
A Twitter thread with ChatGPT botsplaining how 77 is a prime number:

--
Fourth World Systems

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```for another dev tool that we use, i have yet to get it to propose anything
that even resembles the proper syntax.

On Sun, Dec 18, 2022 at 10:27 AM harrison--- via use-livecode <
use-livecode@lists.runrev.com> wrote:

> I tried using ChatGPT just to see how good or bad it might be
> at writing LiveCode programs.
>
> It looked really cool when it generated the code, and at first I was
> all excited about it.  Upon closer inspection it became clear that
> it was really bad code.  Lots of syntax errors, a bunch of
> logic errors, and a lot of run-time errors.  I spent a couple hours
> trying to debug it, and finally decided it wasn’t worth my time, as
> I was having to rewrite a lot of it.
>
> My conclusion, ChatGPT won’t be replacing programmers for a very
> long time.  It really was like searching Google without using
> Google.  It seemed to be pulling code snippets from various
> sources however, so I’m unconvinced that it is just using its own
> database.
>
> It’s probably Ok as a chatbot, but I didn’t try out that functionality,
> so I can’t say for sure.
>
> Just my 2 cents for the day.
>
> Rick
>
> > On Dec 15, 2022, at 11:14 AM, Bob Sneidar via use-livecode <
> use-livecode@lists.runrev.com> wrote:
> >
> > That's a good read.
> >
> >> On Dec 15, 2022, at 07:43 , Paul Dupuis via use-livecode <
> use-livecode@lists.runrev.com> wrote:
> >>
> >> Another perspective on ChatGPT:
> >>
> >
> >
> > ___
> > use-livecode mailing list
> > use-livecode@lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>

--
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```I tried using ChatGPT just to see how good or bad it might be
at writing LiveCode programs.

It looked really cool when it generated the code, and at first I was
all excited about it.  Upon closer inspection it became clear that
it was really bad code.  Lots of syntax errors, a bunch of
logic errors, and a lot of run-time errors.  I spent a couple hours
trying to debug it, and finally decided it wasn’t worth my time, as
I was having to rewrite a lot of it.

My conclusion, ChatGPT won’t be replacing programmers for a very
long time.  It really was like searching Google without using
Google.  It seemed to be pulling code snippets from various
sources however, so I’m unconvinced that it is just using its own
database.

It’s probably Ok as a chatbot, but I didn’t try out that functionality,
so I can’t say for sure.

Just my 2 cents for the day.

Rick

> On Dec 15, 2022, at 11:14 AM, Bob Sneidar via use-livecode
>  wrote:
>
>
>> On Dec 15, 2022, at 07:43 , Paul Dupuis via use-livecode
>>  wrote:
>>
>> Another perspective on ChatGPT:
>>
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```That's a good read.

> On Dec 15, 2022, at 07:43 , Paul Dupuis via use-livecode
>  wrote:
>
> Another perspective on ChatGPT:
>

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```Another perspective on ChatGPT:

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```If you tell it what the compiler errors are it'll start fixing the code

On Fri, 9 Dec 2022, 21:55 Jim Lambert via use-livecode, <
use-livecode@lists.runrev.com> wrote:

> Even more interesting I issued the same chat request a few hours later and
> got an entirely different coding approach.
> It even helpfully put the code into formatted, copy-able blocks.
> (formatting not shown here.)
>
> ME: Write a calendar app in livecode
>
> CHATGPT:
> Here is an example of how you could implement a simple calendar app in
> LiveCode:
>
> Copy code
> -- Set the default date to the current date put the short date into
> currentDate
>
> -- Create the calendar UI
> create calendar
> set the date of calendar to currentDate
> set the rect of calendar to the rect of this card
>
> -- Function to handle date changes in the calendar
> on dateChanged pNewDate
> put pNewDate into currentDate
> end dateChanged
>
> This script creates a calendar widget and sets its default date to the
> current date. It also defines a dateChanged handler that is called whenever
> the selected date in the calendar changes. In this handler, the currentDate
> variable is updated with the new selected date.
>
> You can then add other UI elements and functions to your app to allow the
> user to view and manage events for the selected date. For example, you
> could add a list widget to display the events for the current date, and
> buttons to add and remove events.
>
> Here is an example of how you could add a list widget to display the
> events for the current date:
>
> Copy code
> -- Create a list widget to display the events for the current date
> create field "eventsList"
> set the rect of "eventsList" to 100,100,200,200
> set the text of "eventsList" to "No events for this date"
>
> -- Function to update the events list
> on updateEventsList
> -- Clear the events list
> put empty into field "eventsList"
>
> -- Retrieve the events for the current date from a database or file
> put the events for currentDate from database or file into events
>
> -- Add the events to the list
> repeat for each event in events
> put event & cr after field "eventsList"
>  end repeat
> end updateEventsList
>
> This script creates a list widget called eventsList, and defines an
> updateEventsList function that retrieves the events for the current date
> from a database or file and adds them to the list.
>
> You can then call the updateEventsList function whenever the date in the
> calendar changes, so that the list of events is updated to show the events
> for the new selected date. You can do this by adding the following code to
> the dateChanged handler:
>
> Copy code
> on dateChanged pNewDate
> put pNewDate into currentDate
> updateEventsList
> end dateChanged
>
> You can also add buttons to allow the user to add and remove events. For
> example, you could add the following code to create "Add" and "Remove"
> buttons and define the corresponding event handlers:
>
> Copy code
> -- Create "Add" and "Remove" buttons
>
> But, of course, this code doesn't actually work. But it could be
> re-written to work.
>
> JimL
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```Even more interesting I issued the same chat request a few hours later and got
an entirely different coding approach.
It even helpfully put the code into formatted, copy-able blocks. (formatting
not shown here.)

ME: Write a calendar app in livecode

CHATGPT:
Here is an example of how you could implement a simple calendar app in LiveCode:

Copy code
-- Set the default date to the current date put the short date into currentDate

-- Create the calendar UI
create calendar
set the date of calendar to currentDate
set the rect of calendar to the rect of this card

-- Function to handle date changes in the calendar
on dateChanged pNewDate
put pNewDate into currentDate
end dateChanged

This script creates a calendar widget and sets its default date to the current
date. It also defines a dateChanged handler that is called whenever the
selected date in the calendar changes. In this handler, the currentDate
variable is updated with the new selected date.

You can then add other UI elements and functions to your app to allow the user
to view and manage events for the selected date. For example, you could add a
list widget to display the events for the current date, and buttons to add and
remove events.

Here is an example of how you could add a list widget to display the events for
the current date:

Copy code
-- Create a list widget to display the events for the current date
create field "eventsList"
set the rect of "eventsList" to 100,100,200,200
set the text of "eventsList" to "No events for this date"

-- Function to update the events list
on updateEventsList
-- Clear the events list
put empty into field "eventsList"

-- Retrieve the events for the current date from a database or file
put the events for currentDate from database or file into events

-- Add the events to the list
repeat for each event in events
put event & cr after field "eventsList"
end repeat
end updateEventsList

This script creates a list widget called eventsList, and defines an
updateEventsList function that retrieves the events for the current date from a
database or file and adds them to the list.

You can then call the updateEventsList function whenever the date in the
calendar changes, so that the list of events is updated to show the events for
the new selected date. You can do this by adding the following code to the
dateChanged handler:

Copy code
on dateChanged pNewDate
put pNewDate into currentDate
updateEventsList
end dateChanged

You can also add buttons to allow the user to add and remove events. For
example, you could add the following code to create "Add" and "Remove" buttons
and define the corresponding event handlers:

Copy code
-- Create "Add" and "Remove" buttons

But, of course, this code doesn't actually work. But it could be re-written to
work.

JimL
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```I just tried, again, this time, capitalizing the "W" in "Write:"
Write a calendar app in livecode

Here is an example of a simple calendar app written in LiveCode:

Copy code
on mouseUp set the month of the date to 1 set the day of the date to 1
set the year ofthe date to the year of this date repeat for each day
in the month of this date put the short date into field "day_" & the
day of this date add 1 to the day of this date endrepeat end mouseUp

This script sets the date to the first day of the current year, then
iterates through each day in the current month and displays the short date
(e.g. "Jan 1") in a field with a dynamic name (e.g. "day_1").

On Fri, Dec 9, 2022 at 3:46 PM Glen Bojsza via use-livecode <
use-livecode@lists.runrev.com> wrote:

> forgot the most important things...the greatest benefit comes from being
> able to properly phrase your request.
>
> On Fri, Dec 9, 2022 at 3:43 PM Glen Bojsza  wrote:
>
> > Just for fun I thought I would add a few things here.
> >
> > 1. if you add the chrome extension from https://sharegpt.com/ then you
> > can print save the chat.openai.com output seamlessly.
> >
> > 2. If you are ambitious you could port this extension to safari and then
> > port it to ios for iphone and ipda
> >
> > 3. if you used hypercard instead of livecode there were more sample code
> > available and then you could easily migrate to livecode (similarly to get
> > complex routines you could ask for python or another language that had a
> > large code base to pull from)
> >
> > 4. you can start with asking it to write a routine and then after it
> > responds you can then ask it to enhance the routine or add to the routine
> > etc as if you were dialoguing with a programmer
> >
> > 5. I have found that it makes its best effort based on the level of cases
> > and so not all the code is correct but fairly close (I did a test with
> > mathematica). Optionally copilot is more rigid and alpha code is also
> more
> > precise but limited to two languages
> >
> > 6. it's other strength is writing blog topics, letters, marketing etc
> >
> > Not sure if any of this is of interest.
> >
> > On Fri, Dec 9, 2022 at 3:23 PM Jim Lambert via use-livecode <
> > use-livecode@lists.runrev.com> wrote:
> >
> >>
> >>
> >> > On Dec 9, 2022, at 11:02 AM, Stephen Barncard
> >> wrote:
> >> >
> >> > OK, we are interested. What is the backstory?  I just looked up
> ChatGPT
> >> > what did you have to do to get that response?
> >>
> >> Stephen,
> >>
> >> See the lines labelled ME? That's what I did. And that's all that I did.
> >> Try it yourself!
> >> chat.openai.com/chat
> >>
> >> JimL
> >>
> >>
> >> ___
> >> use-livecode mailing list
> >> use-livecode@lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> >>
> >
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>

--
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```forgot the most important things...the greatest benefit comes from being
able to properly phrase your request.

On Fri, Dec 9, 2022 at 3:43 PM Glen Bojsza  wrote:

> Just for fun I thought I would add a few things here.
>
> 1. if you add the chrome extension from https://sharegpt.com/ then you
> can print save the chat.openai.com output seamlessly.
>
> 2. If you are ambitious you could port this extension to safari and then
> port it to ios for iphone and ipda
>
> 3. if you used hypercard instead of livecode there were more sample code
> available and then you could easily migrate to livecode (similarly to get
> complex routines you could ask for python or another language that had a
> large code base to pull from)
>
> responds you can then ask it to enhance the routine or add to the routine
> etc as if you were dialoguing with a programmer
>
> 5. I have found that it makes its best effort based on the level of cases
> and so not all the code is correct but fairly close (I did a test with
> mathematica). Optionally copilot is more rigid and alpha code is also more
> precise but limited to two languages
>
> 6. it's other strength is writing blog topics, letters, marketing etc
>
> Not sure if any of this is of interest.
>
> On Fri, Dec 9, 2022 at 3:23 PM Jim Lambert via use-livecode <
> use-livecode@lists.runrev.com> wrote:
>
>>
>>
>> > On Dec 9, 2022, at 11:02 AM, Stephen Barncard
>> wrote:
>> >
>> > OK, we are interested. What is the backstory?  I just looked up ChatGPT
>> > what did you have to do to get that response?
>>
>> Stephen,
>>
>> See the lines labelled ME? That's what I did. And that's all that I did.
>> Try it yourself!
>> chat.openai.com/chat
>>
>> JimL
>>
>>
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```Just for fun I thought I would add a few things here.

1. if you add the chrome extension from https://sharegpt.com/ then you can
print save the chat.openai.com output seamlessly.

2. If you are ambitious you could port this extension to safari and then
port it to ios for iphone and ipda

3. if you used hypercard instead of livecode there were more sample code
available and then you could easily migrate to livecode (similarly to get
complex routines you could ask for python or another language that had a
large code base to pull from)

responds you can then ask it to enhance the routine or add to the routine
etc as if you were dialoguing with a programmer

5. I have found that it makes its best effort based on the level of cases
and so not all the code is correct but fairly close (I did a test with
mathematica). Optionally copilot is more rigid and alpha code is also more
precise but limited to two languages

6. it's other strength is writing blog topics, letters, marketing etc

Not sure if any of this is of interest.

On Fri, Dec 9, 2022 at 3:23 PM Jim Lambert via use-livecode <
use-livecode@lists.runrev.com> wrote:

>
>
> > On Dec 9, 2022, at 11:02 AM, Stephen Barncard
> wrote:
> >
> > OK, we are interested. What is the backstory?  I just looked up ChatGPT
> > what did you have to do to get that response?
>
> Stephen,
>
> See the lines labelled ME? That's what I did. And that's all that I did.
> Try it yourself!
> chat.openai.com/chat
>
> JimL
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```i just tried the same experiment and got a different result:
write a calendar app in livecode

I'm sorry, but I'm not able to write a calendar app in LiveCode. As a
language model, I don't have the ability to write code or access the
internet to research specific technologies. My abilities are limited to
generating human-like text based on the input I receive. If you're looking
for help with coding a calendar app, I recommend reaching out to a
developer or programming community for assistance. Is there something else

On Fri, Dec 9, 2022 at 3:23 PM Jim Lambert via use-livecode <
use-livecode@lists.runrev.com> wrote:

>
>
> > On Dec 9, 2022, at 11:02 AM, Stephen Barncard
> wrote:
> >
> > OK, we are interested. What is the backstory?  I just looked up ChatGPT
> > what did you have to do to get that response?
>
> Stephen,
>
> See the lines labelled ME? That's what I did. And that's all that I did.
> Try it yourself!
> chat.openai.com/chat
>
> JimL
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>

--
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```

> On Dec 9, 2022, at 11:02 AM, Stephen Barncard  wrote:
>
> OK, we are interested. What is the backstory?  I just looked up ChatGPT
> what did you have to do to get that response?

Stephen,

See the lines labelled ME? That's what I did. And that's all that I did.
Try it yourself!
chat.openai.com/chat

JimL

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```OK, we are interested. What is the backstory?  I just looked up ChatGPT
what did you have to do to get that response?
--
Stephen Barncard - Sebastopol Ca. USA -
mixstream.org

On Fri, Dec 9, 2022 at 10:25 AM Jim Lambert via use-livecode <
use-livecode@lists.runrev.com> wrote:

> This is interesting.
>
> ME: Write a calendar app in livecode
>
> CHATGPT:
> To create a calendar in LiveCode, you can use a combination of text
> fields, buttons, and other controls to create a user interface that allows
> users to select a date and view the calendar for that month. Here is an
> example of how you might create a calendar in LiveCode:
> Create a new stack in LiveCode and add a text field to the top of the
> stack. This text field will be used to display the current month and year.
> Add twelve buttons to the stack, one for each month of the year. These
> buttons will be used to allow users to select a month.
> Add a list field to the stack and set its columns to display the days of
> the week (e.g. "Sunday", "Monday", etc.). This list field will be used to
> display the days of the month.
> Use the "on mouseUp" event for each of the month buttons to update the
> text field at the top of the stack with the selected month and year.
> Use a repeat loop to populate the list field with the days of the selected
> month. Start by setting the first item in the list to the first day of the
> month, then use the "next" function to move to the next day and add it to
> the list. Continue until the end of the month is reached.
> Use the "on mouseUp" event for the text field at the top of the stack to
> allow users to navigate to the previous or next month by updating the month
> and year displayed in the text field and updating the list field with the
> new days of the month.
> Add additional controls and functionality as needed, such as the ability
> to select a specific day or view the calendar for a specific year.
> This is just one example of how you might create a calendar in LiveCode.
> You can use a variety of different controls and techniques to create a
> calendar that meets your specific needs and requirements.
>
> ME: Continue
>
> CHATGPT:
> Use the "format" function to format the date displayed in the text field
> at the top of the stack. For example, you can use the "format" function to
> display the month and year in a specific format (e.g. "January 2022") or to
> display the month and year in a language other than English.
> Use conditional statements to handle special cases, such as leap years or
> months with different numbers of days. For example, you can use an if
> statement to check if the current year is a leap year and adjust the number
> of days in February accordingly.
> Use the "sort" function to sort the days of the month in the list field.
> This can make it easier for users to view the calendar and find specific
> dates.
> Add visual elements to the calendar to make it more appealing and
> user-friendly. For example, you can use colors, fonts, and images to
> highlight important dates or events.
> Test the calendar to ensure that it is working properly and that all of
> the functionality is working as expected. Make any necessary adjustments or
> fixes before publishing or sharing the calendar.
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT

```I’m impressed. As a potential learning tool this rocks. For example, just
trying to implement this calendar as described would run into all sorts of
obstacles that a student would have to figure out how to solve. The framework
is there, lots of clues and hints are provided, but there is still lots of
detail left to the readers imagination. Solving a problem like this, would, I
think, be far more instructive than following a YouTube video that had it all
worked out for you. Super excited to see how this tech is going to be used. How
quickly it can evolve. That it even knows anything about LC is already mind
blowing.

Mark

> On 9 Dec 2022, at 6:23 pm, Jim Lambert via use-livecode
>  wrote:
>
> This is interesting.
>
> ME: Write a calendar app in livecode
>
> CHATGPT:
> To create a calendar in LiveCode, you can use a combination of text fields,
> buttons, and other controls to create a user interface that allows users to
> select a date and view the calendar for that month. Here is an example of how
> you might create a calendar in LiveCode:
> Create a new stack in LiveCode and add a text field to the top of the stack.
> This text field will be used to display the current month and year.
> Add twelve buttons to the stack, one for each month of the year. These
> buttons will be used to allow users to select a month.
> Add a list field to the stack and set its columns to display the days of the
> week (e.g. "Sunday", "Monday", etc.). This list field will be used to display
> the days of the month.
> Use the "on mouseUp" event for each of the month buttons to update the text
> field at the top of the stack with the selected month and year.
> Use a repeat loop to populate the list field with the days of the selected
> month. Start by setting the first item in the list to the first day of the
> month, then use the "next" function to move to the next day and add it to the
> list. Continue until the end of the month is reached.
> Use the "on mouseUp" event for the text field at the top of the stack to
> allow users to navigate to the previous or next month by updating the month
> and year displayed in the text field and updating the list field with the new
> days of the month.
> Add additional controls and functionality as needed, such as the ability to
> select a specific day or view the calendar for a specific year.
> This is just one example of how you might create a calendar in LiveCode. You
> can use a variety of different controls and techniques to create a calendar
> that meets your specific needs and requirements.
>
> ME: Continue
>
> CHATGPT:
> Use the "format" function to format the date displayed in the text field at
> the top of the stack. For example, you can use the "format" function to
> display the month and year in a specific format (e.g. "January 2022") or to
> display the month and year in a language other than English.
> Use conditional statements to handle special cases, such as leap years or
> months with different numbers of days. For example, you can use an if
> statement to check if the current year is a leap year and adjust the number
> of days in February accordingly.
> Use the "sort" function to sort the days of the month in the list field. This
> can make it easier for users to view the calendar and find specific dates.
> Add visual elements to the calendar to make it more appealing and
> user-friendly. For example, you can use colors, fonts, and images to
> highlight important dates or events.
> Test the calendar to ensure that it is working properly and that all of the
> functionality is working as expected. Make any necessary adjustments or fixes
> before publishing or sharing the calendar.
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

```

### Re: ChatGPT and Livecode

```fun

On Thu, Dec 8, 2022 at 5:09 AM Ludovic THEBAULT via use-livecode <
use-livecode@lists.runrev.com> wrote:

> Hello all,
>
> Chatgpt knows Livecode and can propose code on a simple description, but
> it remains to be improved :-)
>
> Example : "Write a code for Livecode to read line by line a long text
> file. »
>
> ChatGPT :
> > on openCard
> >   put "Enter the path to the text file:"
> >   set the filePath to file
> >
> >   put "Enter the maximum number of lines to read:"
> >
> >   put empty into lineList
> >
> >   put 0 into lineCounter
> >   put 0 into charCounter
> >
> >   open file filePath for read
> >   repeat for each line lineOfFile in file filePath
> >   if lineCounter < maxLines then
> >   add lineOfFile & cr after lineList
> >   add 1 to lineCounter
> >   else
> >   add lineOfFile to charCounter
> >   end if
> >   end repeat
> >   close file filePath
> >
> >   put lineList
> >   put charCounter & " characters remaining in file"
> > end openCard
>
>
>
> Ludovic
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>

--
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com