WeixiangYan/CodeTransOcean huggingface dataset:
Task: Comma quibbling





Java: public class Quibbler {

	public static String quibble(String[] words) {
		String qText = "{";
		for(int wIndex = 0; wIndex < words.length; wIndex++) {
			qText += words[wIndex] + (wIndex == words.length-1 ? "" : 
						  wIndex == words.length-2 ? " and " :
						  ", ";
		}
		qText += "}";
		return qText;
	}
	
	public static void main(String[] args) {
		System.out.println(quibble(new String[]{}));
		System.out.println(quibble(new String[]{"ABC"}));
		System.out.println(quibble(new String[]{"ABC", "DEF"}));
		System.out.println(quibble(new String[]{"ABC", "DEF", "G"}));
		System.out.println(quibble(new String[]{"ABC", "DEF", "G", "H"}));
	}
}






Fortran:       SUBROUTINE QUIBBLE(TEXT,OXFORDIAN)	
       CHARACTER*(*) TEXT	
       LOGICAL OXFORDIAN	
       INTEGER IST(6),LST(6)	
       INTEGER N,L,I		
       INTEGER L1,L2		
       INTEGER MSG		
       COMMON /IODEV/MSG	
Chop the text into words.
        N = 0		
        L = LEN(TEXT)	
        L2 = 0		
   10   L1 = L2		
   11   L1 = L1 + 1		
        IF (L1.GT.L) GO TO 20		
        IF (TEXT(L1:L1).LE." ") GO TO 11	
        L2 = L1			
   12   L2 = L2 + 1		
        IF (L2.GT.L) GO TO 13	
        IF (TEXT(L2:L2).GT." ") GO TO 12	
   13   N = N + 1			
        IST(N) = L1		
        LST(N) = L2 - 1		
        IF (L2.LT.L) GO TO 10	
Comma time...
   20   WRITE (MSG,21) "{"	
   21   FORMAT (A,$)		
        DO I = 1,N		
          IF (I.GT.1) THEN		
            IF (I.LT.N) THEN			
              WRITE (MSG,21) ", "			
            ELSE IF (OXFORDIAN) THEN		
              WRITE (MSG,21) ", and "			
            ELSE				
              WRITE (MSG,21) " and "			
            END IF				
          END IF			
          WRITE (MSG,21) TEXT(IST(I):LST(I))	
        END DO			
        WRITE (MSG,"('}')")	
      END		

      PROGRAM ENCOMMA	
      CHARACTER*(666) TEXT	
      INTEGER KBD,MSG,INF	
      COMMON /IODEV/MSG,KBD	
      KBD = 5	
      MSG = 6	
      INF = 10	
      OPEN (INF,FILE="List.txt",ACTION = "READ")	

   10 WRITE (MSG,11) "To insert commas into lists..."	
   11 FORMAT (A)			
   12 READ (INF,11,END = 20) TEXT	
      CALL QUIBBLE(TEXT,.FALSE.)	
      GO TO 12				

   20 REWIND (INF)			
      WRITE (MSG,11)			
      WRITE (MSG,11) "Oxford style..."	
   21 READ (INF,11,END = 30) TEXT	
      CALL QUIBBLE(TEXT,.TRUE.)		
      GO TO 21				

Closedown
   30 END
Task: Comma quibbling







Python: fun quibble(s):
    let result = s.join(' and ').replace(|| and ||, ", ", length(s) - 1)
    return "{ $result }"

let s = [
    []
    ["ABC"]
    ["ABC", "DEF"]
    ["ABC", "DEF", "G", "H"]
]

for i in s:
    print(quibble i)




Fortran:       SUBROUTINE QUIBBLE(TEXT,OXFORDIAN)	
       CHARACTER*(*) TEXT	
       LOGICAL OXFORDIAN	
       INTEGER IST(6),LST(6)	
       INTEGER N,L,I		
       INTEGER L1,L2		
       INTEGER MSG		
       COMMON /IODEV/MSG	
Chop the text into words.
        N = 0		
        L = LEN(TEXT)	
        L2 = 0		
   10   L1 = L2		
   11   L1 = L1 + 1		
        IF (L1.GT.L) GO TO 20		
        IF (TEXT(L1:L1).LE." ") GO TO 11	
        L2 = L1			
   12   L2 = L2 + 1		
        IF (L2.GT.L) GO TO 13	
        IF (TEXT(L2:L2).GT." ") GO TO 12	
   13   N = N + 1			
        IST(N) = L1		
        LST(N) = L2 - 1		
        IF (L2.LT.L) GO TO 10	
Comma time...
   20   WRITE (MSG,21) "{"	
   21   FORMAT (A,$)		
        DO I = 1,N		
          IF (I.GT.1) THEN		
            IF (I.LT.N) THEN			
              WRITE (MSG,21) ", "			
            ELSE IF (OXFORDIAN) THEN		
              WRITE (MSG,21) ", and "			
            ELSE				
              WRITE (MSG,21) " and "			
            END IF				
          END IF			
          WRITE (MSG,21) TEXT(IST(I):LST(I))	
        END DO			
        WRITE (MSG,"('}')")	
      END		

      PROGRAM ENCOMMA	
      CHARACTER*(666) TEXT	
      INTEGER KBD,MSG,INF	
      COMMON /IODEV/MSG,KBD	
      KBD = 5	
      MSG = 6	
      INF = 10	
      OPEN (INF,FILE="List.txt",ACTION = "READ")	

   10 WRITE (MSG,11) "To insert commas into lists..."	
   11 FORMAT (A)			
   12 READ (INF,11,END = 20) TEXT	
      CALL QUIBBLE(TEXT,.FALSE.)	
      GO TO 12				

   20 REWIND (INF)			
      WRITE (MSG,11)			
      WRITE (MSG,11) "Oxford style..."	
   21 READ (INF,11,END = 30) TEXT	
      CALL QUIBBLE(TEXT,.TRUE.)		
      GO TO 21				

Closedown
   30 END
Task: Comma quibbling








VB: Option Explicit

Sub Main()
   Debug.Print Quibbling("")
   Debug.Print Quibbling("ABC")
   Debug.Print Quibbling("ABC, DEF")
   Debug.Print Quibbling("ABC, DEF, G, H")
   Debug.Print Quibbling("ABC, DEF, G, H, IJKLM, NO, PQRSTUV")
End Sub

Private Function Quibbling(MyString As String) As String
Dim s As String, n As Integer
   s = "{" & MyString & "}": n = InStrRev(s, ",")
   If n > 0 Then s = Left(s, n - 1) & " and " & Right(s, Len(s) - (n + 1))
   Quibbling = s
End Function



Fortran:       SUBROUTINE QUIBBLE(TEXT,OXFORDIAN)	
       CHARACTER*(*) TEXT	
       LOGICAL OXFORDIAN	
       INTEGER IST(6),LST(6)	
       INTEGER N,L,I		
       INTEGER L1,L2		
       INTEGER MSG		
       COMMON /IODEV/MSG	
Chop the text into words.
        N = 0		
        L = LEN(TEXT)	
        L2 = 0		
   10   L1 = L2		
   11   L1 = L1 + 1		
        IF (L1.GT.L) GO TO 20		
        IF (TEXT(L1:L1).LE." ") GO TO 11	
        L2 = L1			
   12   L2 = L2 + 1		
        IF (L2.GT.L) GO TO 13	
        IF (TEXT(L2:L2).GT." ") GO TO 12	
   13   N = N + 1			
        IST(N) = L1		
        LST(N) = L2 - 1		
        IF (L2.LT.L) GO TO 10	
Comma time...
   20   WRITE (MSG,21) "{"	
   21   FORMAT (A,$)		
        DO I = 1,N		
          IF (I.GT.1) THEN		
            IF (I.LT.N) THEN			
              WRITE (MSG,21) ", "			
            ELSE IF (OXFORDIAN) THEN		
              WRITE (MSG,21) ", and "			
            ELSE				
              WRITE (MSG,21) " and "			
            END IF				
          END IF			
          WRITE (MSG,21) TEXT(IST(I):LST(I))	
        END DO			
        WRITE (MSG,"('}')")	
      END		

      PROGRAM ENCOMMA	
      CHARACTER*(666) TEXT	
      INTEGER KBD,MSG,INF	
      COMMON /IODEV/MSG,KBD	
      KBD = 5	
      MSG = 6	
      INF = 10	
      OPEN (INF,FILE="List.txt",ACTION = "READ")	

   10 WRITE (MSG,11) "To insert commas into lists..."	
   11 FORMAT (A)			
   12 READ (INF,11,END = 20) TEXT	
      CALL QUIBBLE(TEXT,.FALSE.)	
      GO TO 12				

   20 REWIND (INF)			
      WRITE (MSG,11)			
      WRITE (MSG,11) "Oxford style..."	
   21 READ (INF,11,END = 30) TEXT	
      CALL QUIBBLE(TEXT,.TRUE.)		
      GO TO 21				

Closedown
   30 END
Task: Comma quibbling






PHP: <?php

function quibble($arr){

  $words = count($arr);

  if($words == 0){
    return '{}';
  }elseif($words == 1){
    return '{'.$arr[0].'}';
  }elseif($words == 2){
    return '{'.$arr[0].' and '.$arr[1].'}';
  }else{
    return '{'.implode(', ',  array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
  }

}


$tests = [
  [],
  ["ABC"],
  ["ABC", "DEF"],
  ["ABC", "DEF", "G", "H"] 
];

foreach ($tests as $test) {
  echo quibble($test) . PHP_EOL;
}





Fortran:       SUBROUTINE QUIBBLE(TEXT,OXFORDIAN)	
       CHARACTER*(*) TEXT	
       LOGICAL OXFORDIAN	
       INTEGER IST(6),LST(6)	
       INTEGER N,L,I		
       INTEGER L1,L2		
       INTEGER MSG		
       COMMON /IODEV/MSG	
Chop the text into words.
        N = 0		
        L = LEN(TEXT)	
        L2 = 0		
   10   L1 = L2		
   11   L1 = L1 + 1		
        IF (L1.GT.L) GO TO 20		
        IF (TEXT(L1:L1).LE." ") GO TO 11	
        L2 = L1			
   12   L2 = L2 + 1		
        IF (L2.GT.L) GO TO 13	
        IF (TEXT(L2:L2).GT." ") GO TO 12	
   13   N = N + 1			
        IST(N) = L1		
        LST(N) = L2 - 1		
        IF (L2.LT.L) GO TO 10	
Comma time...
   20   WRITE (MSG,21) "{"	
   21   FORMAT (A,$)		
        DO I = 1,N		
          IF (I.GT.1) THEN		
            IF (I.LT.N) THEN			
              WRITE (MSG,21) ", "			
            ELSE IF (OXFORDIAN) THEN		
              WRITE (MSG,21) ", and "			
            ELSE				
              WRITE (MSG,21) " and "			
            END IF				
          END IF			
          WRITE (MSG,21) TEXT(IST(I):LST(I))	
        END DO			
        WRITE (MSG,"('}')")	
      END		

      PROGRAM ENCOMMA	
      CHARACTER*(666) TEXT	
      INTEGER KBD,MSG,INF	
      COMMON /IODEV/MSG,KBD	
      KBD = 5	
      MSG = 6	
      INF = 10	
      OPEN (INF,FILE="List.txt",ACTION = "READ")	

   10 WRITE (MSG,11) "To insert commas into lists..."	
   11 FORMAT (A)			
   12 READ (INF,11,END = 20) TEXT	
      CALL QUIBBLE(TEXT,.FALSE.)	
      GO TO 12				

   20 REWIND (INF)			
      WRITE (MSG,11)			
      WRITE (MSG,11) "Oxford style..."	
   21 READ (INF,11,END = 30) TEXT	
      CALL QUIBBLE(TEXT,.TRUE.)		
      GO TO 21				

Closedown
   30 END
Task: Comma quibbling

C: #include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *quib(const char **strs, size_t size)
{

    size_t len = 3 + ((size > 1) ? (2 * size + 1) : 0);
    size_t i;

    for (i = 0; i < size; i++)
        len += strlen(strs[i]);

    char *s = malloc(len * sizeof(*s));
    if (!s)
    {
        perror("Can't allocate memory!\n");
        exit(EXIT_FAILURE);
    }

    strcpy(s, "{");
    switch (size) {
        case 0:  break;
        case 1:  strcat(s, strs[0]);
                 break;
        default: for (i = 0; i < size - 1; i++)
                 {
                     strcat(s, strs[i]);
                     if (i < size - 2)
                         strcat(s, ", ");
                     else
                         strcat(s, " and ");
                 }
                 strcat(s, strs[i]);
                 break;
    }  
    strcat(s, "}");
    return s;
}

int main(void)
{
    const char *test[] = {"ABC", "DEF", "G", "H"};
    char *s;

    for (size_t i = 0; i < 5; i++)
    {
        s = quib(test, i);
        printf("%s\n", s);
        free(s);
    }
    return EXIT_SUCCESS;
}









COBOL:        >>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. comma-quibbling-test.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
    FUNCTION comma-quibbling
    .
DATA DIVISION.
WORKING-STORAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

PROCEDURE DIVISION.
    MOVE "ABC" TO strs (1)
    MOVE "DEF" TO strs (2)
    MOVE "G" TO strs (3)
    MOVE "H" TO strs (4)

    PERFORM VARYING strs-len FROM 0 BY 1 UNTIL strs-len > 4
        DISPLAY FUNCTION comma-quibbling(strs-area)
    END-PERFORM
    .
END PROGRAM comma-quibbling-test.

 
IDENTIFICATION DIVISION.
FUNCTION-ID. comma-quibbling.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01  i                             PIC 9.

01  num-extra-words               PIC 9.

LINKAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

01  str                           PIC X(50).

PROCEDURE DIVISION USING strs-area RETURNING str.
    EVALUATE strs-len
        WHEN ZERO
            MOVE "{}" TO str
            GOBACK

        WHEN 1
            MOVE FUNCTION CONCATENATE("{", FUNCTION TRIM(strs (1)), "}")
                TO str
            GOBACK
    END-EVALUATE

    MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (strs-len - 1)),
        " and ", FUNCTION TRIM(strs (strs-len)), "}")
        TO str

    IF strs-len > 2
        SUBTRACT 2 FROM strs-len GIVING num-extra-words
        PERFORM VARYING i FROM num-extra-words BY -1 UNTIL i = 0
            MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (i)), ", ", str)
                TO str
        END-PERFORM
    END-IF
    
    MOVE FUNCTION CONCATENATE("{", str) TO str
    .
END FUNCTION comma-quibbling.
Task: Comma quibbling



C#: using System;
using System.Linq;

namespace CommaQuibbling
{
    internal static class Program
    {
        #region Static Members
	private static string Quibble(string[] input)
	{
            return
                String.Format("{{{0}}}",
                    String.Join("",
                        input.Reverse().Zip(
                            new [] { "", " and " }.Concat(Enumerable.Repeat(", ", int.MaxValue)),
                            (x, y) => x + y).Reverse()));
	}


        private static void Main()
        {
            Console.WriteLine( Quibble( new string[] {} ) );
            Console.WriteLine( Quibble( new[] {"ABC"} ) );
            Console.WriteLine( Quibble( new[] {"ABC", "DEF"} ) );
            Console.WriteLine( Quibble( new[] {"ABC", "DEF", "G", "H"} ) );

            Console.WriteLine( "< Press Any Key >" );
            Console.ReadKey();
        }

        #endregion
    }
}







COBOL:        >>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. comma-quibbling-test.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
    FUNCTION comma-quibbling
    .
DATA DIVISION.
WORKING-STORAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

PROCEDURE DIVISION.
    MOVE "ABC" TO strs (1)
    MOVE "DEF" TO strs (2)
    MOVE "G" TO strs (3)
    MOVE "H" TO strs (4)

    PERFORM VARYING strs-len FROM 0 BY 1 UNTIL strs-len > 4
        DISPLAY FUNCTION comma-quibbling(strs-area)
    END-PERFORM
    .
END PROGRAM comma-quibbling-test.

 
IDENTIFICATION DIVISION.
FUNCTION-ID. comma-quibbling.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01  i                             PIC 9.

01  num-extra-words               PIC 9.

LINKAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

01  str                           PIC X(50).

PROCEDURE DIVISION USING strs-area RETURNING str.
    EVALUATE strs-len
        WHEN ZERO
            MOVE "{}" TO str
            GOBACK

        WHEN 1
            MOVE FUNCTION CONCATENATE("{", FUNCTION TRIM(strs (1)), "}")
                TO str
            GOBACK
    END-EVALUATE

    MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (strs-len - 1)),
        " and ", FUNCTION TRIM(strs (strs-len)), "}")
        TO str

    IF strs-len > 2
        SUBTRACT 2 FROM strs-len GIVING num-extra-words
        PERFORM VARYING i FROM num-extra-words BY -1 UNTIL i = 0
            MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (i)), ", ", str)
                TO str
        END-PERFORM
    END-IF
    
    MOVE FUNCTION CONCATENATE("{", str) TO str
    .
END FUNCTION comma-quibbling.
Task: Comma quibbling


C++: #include <iostream>

template<class T>
void quibble(std::ostream& o, T i, T e) {
  o << "{";
  if (e != i) {
    T n = i++;
    const char* more = "";
    while (e != i) {
      o << more << *n;
      more = ", ";
      n = i++;
    }
    o << (*more?" and ":"") << *n;
  }
  o << "}";
}

int main(int argc, char** argv) {
  char const* a[] = {"ABC","DEF","G","H"};
  for (int i=0; i<5; i++) {
    quibble(std::cout, a, a+i);
    std::cout << std::endl;
  }
  return 0;
}








COBOL:        >>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. comma-quibbling-test.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
    FUNCTION comma-quibbling
    .
DATA DIVISION.
WORKING-STORAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

PROCEDURE DIVISION.
    MOVE "ABC" TO strs (1)
    MOVE "DEF" TO strs (2)
    MOVE "G" TO strs (3)
    MOVE "H" TO strs (4)

    PERFORM VARYING strs-len FROM 0 BY 1 UNTIL strs-len > 4
        DISPLAY FUNCTION comma-quibbling(strs-area)
    END-PERFORM
    .
END PROGRAM comma-quibbling-test.

 
IDENTIFICATION DIVISION.
FUNCTION-ID. comma-quibbling.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01  i                             PIC 9.

01  num-extra-words               PIC 9.

LINKAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

01  str                           PIC X(50).

PROCEDURE DIVISION USING strs-area RETURNING str.
    EVALUATE strs-len
        WHEN ZERO
            MOVE "{}" TO str
            GOBACK

        WHEN 1
            MOVE FUNCTION CONCATENATE("{", FUNCTION TRIM(strs (1)), "}")
                TO str
            GOBACK
    END-EVALUATE

    MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (strs-len - 1)),
        " and ", FUNCTION TRIM(strs (strs-len)), "}")
        TO str

    IF strs-len > 2
        SUBTRACT 2 FROM strs-len GIVING num-extra-words
        PERFORM VARYING i FROM num-extra-words BY -1 UNTIL i = 0
            MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (i)), ", ", str)
                TO str
        END-PERFORM
    END-IF
    
    MOVE FUNCTION CONCATENATE("{", str) TO str
    .
END FUNCTION comma-quibbling.
Task: Comma quibbling





Java: public class Quibbler {

	public static String quibble(String[] words) {
		String qText = "{";
		for(int wIndex = 0; wIndex < words.length; wIndex++) {
			qText += words[wIndex] + (wIndex == words.length-1 ? "" : 
						  wIndex == words.length-2 ? " and " :
						  ", ";
		}
		qText += "}";
		return qText;
	}
	
	public static void main(String[] args) {
		System.out.println(quibble(new String[]{}));
		System.out.println(quibble(new String[]{"ABC"}));
		System.out.println(quibble(new String[]{"ABC", "DEF"}));
		System.out.println(quibble(new String[]{"ABC", "DEF", "G"}));
		System.out.println(quibble(new String[]{"ABC", "DEF", "G", "H"}));
	}
}





COBOL:        >>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. comma-quibbling-test.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
    FUNCTION comma-quibbling
    .
DATA DIVISION.
WORKING-STORAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

PROCEDURE DIVISION.
    MOVE "ABC" TO strs (1)
    MOVE "DEF" TO strs (2)
    MOVE "G" TO strs (3)
    MOVE "H" TO strs (4)

    PERFORM VARYING strs-len FROM 0 BY 1 UNTIL strs-len > 4
        DISPLAY FUNCTION comma-quibbling(strs-area)
    END-PERFORM
    .
END PROGRAM comma-quibbling-test.

 
IDENTIFICATION DIVISION.
FUNCTION-ID. comma-quibbling.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01  i                             PIC 9.

01  num-extra-words               PIC 9.

LINKAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

01  str                           PIC X(50).

PROCEDURE DIVISION USING strs-area RETURNING str.
    EVALUATE strs-len
        WHEN ZERO
            MOVE "{}" TO str
            GOBACK

        WHEN 1
            MOVE FUNCTION CONCATENATE("{", FUNCTION TRIM(strs (1)), "}")
                TO str
            GOBACK
    END-EVALUATE

    MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (strs-len - 1)),
        " and ", FUNCTION TRIM(strs (strs-len)), "}")
        TO str

    IF strs-len > 2
        SUBTRACT 2 FROM strs-len GIVING num-extra-words
        PERFORM VARYING i FROM num-extra-words BY -1 UNTIL i = 0
            MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (i)), ", ", str)
                TO str
        END-PERFORM
    END-IF
    
    MOVE FUNCTION CONCATENATE("{", str) TO str
    .
END FUNCTION comma-quibbling.
Task: Comma quibbling







Python: fun quibble(s):
    let result = s.join(' and ').replace(|| and ||, ", ", length(s) - 1)
    return "{ $result }"

let s = [
    []
    ["ABC"]
    ["ABC", "DEF"]
    ["ABC", "DEF", "G", "H"]
]

for i in s:
    print(quibble i)



COBOL:        >>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. comma-quibbling-test.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
    FUNCTION comma-quibbling
    .
DATA DIVISION.
WORKING-STORAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

PROCEDURE DIVISION.
    MOVE "ABC" TO strs (1)
    MOVE "DEF" TO strs (2)
    MOVE "G" TO strs (3)
    MOVE "H" TO strs (4)

    PERFORM VARYING strs-len FROM 0 BY 1 UNTIL strs-len > 4
        DISPLAY FUNCTION comma-quibbling(strs-area)
    END-PERFORM
    .
END PROGRAM comma-quibbling-test.

 
IDENTIFICATION DIVISION.
FUNCTION-ID. comma-quibbling.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01  i                             PIC 9.

01  num-extra-words               PIC 9.

LINKAGE SECTION.
01  strs-area.
    03  strs-len                  PIC 9.
    03  strs                      PIC X(5)
                                  OCCURS 0 TO 9 TIMES
                                  DEPENDING ON strs-len.

01  str                           PIC X(50).

PROCEDURE DIVISION USING strs-area RETURNING str.
    EVALUATE strs-len
        WHEN ZERO
            MOVE "{}" TO str
            GOBACK

        WHEN 1
            MOVE FUNCTION CONCATENATE("{", FUNCTION TRIM(strs (1)), "}")
                TO str
            GOBACK
    END-EVALUATE

    MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (strs-len - 1)),
        " and ", FUNCTION TRIM(strs (strs-len)), "}")
        TO str

    IF strs-len > 2
        SUBTRACT 2 FROM strs-len GIVING num-extra-words
        PERFORM VARYING i FROM num-extra-words BY -1 UNTIL i = 0
            MOVE FUNCTION CONCATENATE(FUNCTION TRIM(strs (i)), ", ", str)
                TO str
        END-PERFORM
    END-IF
    
    MOVE FUNCTION CONCATENATE("{", str) TO str
    .
END FUNCTION comma-quibbling.