EXEMPLES
EXEMPLES
  **module** lang = pl
    :- encoding(utf8).
    DOCUMENTATION
      GRAPHIQUES
        https://prolog.developpez.com/cours/
          interface graphique simple : https://jfoutelet.developpez.com/articles/xpce/
          un pb de partage : https://jfoutelet.developpez.com/articles/partage/
          timer
            https://stackoverflow.com/questions/4746989/looking-for-a-xpce-tutorial
            https://depinfo.u-bourgogne.fr/doc/pl-5.0.8/userguide.pdf
              p 278
            exemple
              (object( @my_timer), !, free( @my_timer); true)
              new(@my_timer, my_timer(Step, Delay, Frames, X))
              variable(mytimer, timer, both, "timer lançant l'animation fréquence 20 fois par seconde").
        doc XPCE
          https://www.swi-prolog.org/download/xpce/doc/userguide/userguide.pdf
            chapter 5 simple graphics
            On page 260 there's an example of using a timer to introduce a delay, and page 266 shows using a timer for a blinking graphical.
            On page 40 there's a mention of utilizing 'graphical->flush' to explicitly force redraw right now.
        timers
        quelques personnes
          Pierre Caboche
          Joel Foutelet
          Eric de la Clergerie
            INRIA
    *standard prolog
      notation
        P_DEBUG ::=
          {a1_} :-
            echo {a1_}
              fail
        , nil ::= | []
    preliminary tests
      tests for macros
        notations locales
          test_notation :-
            L = 1 . 2 . 3
              echo L
            L = 1 . L2
              echo L
            L = 1 .. L2
              echo L
            L = 1 . 2 . 3 .. L2
              echo L
            L = 1 . (2 , 3) . 3 .. L2
              echo L
            L = 1 . (2 , 3)
              echo L
            L = 1 .. (2 , 3)
              echo L
            L = 1 . [2 . 3] . 3 .. L2
              echo L
            L = 1 .. [2 . 3]
              echo L
          enlever X de L pour avoir une liste
            DEF_IO enlever, (+X,+L, -Reste)
              in
                X, []
                  []
                    out
                X, X .. L
                  L
                    out
                  !
                    goals
                X, Y .. L
                  Y .. L2
                    out
                  enlever (X, L, L2)
                    goals
          notations pour XPCE
            ' /> ' ::= send ( {a_1}, {a1_} )
            ' += ' ::= new ( {a_1}, {a1_} )
        SEP 1 test de LATER
          AVANT LATER
          LATER
            foo
            ceci est un commentaire
          autre chose
          LATER
            baz
            bat
          qq chose intermédiaire
          récupération de la liste LATER
            LATER_E
        infos de base
          bar.
          bat
          bat ('écho').
          baz.
          baz (1,2,_,_,_,_)
          foo (_)
          x
          y
          z
          t
          u
          v (_, _)
        spe :-
          bar,,
          baz
          bat,
        test logique
          foo (a, b) :-
            IF a = b
              foobar (a)
              !
                barfoo (b)
        spe :-
          bar,,
          bar
          bar,
          baz (
            X
            Y
              u
                v (
                  a
                  b
            z
              t
          baz (
            X
            [
              Y
              | Z
          foo (
            baz(
              X
              [
                Y
                  |
                    Z
            baz(
              [
                X
                  Y
                    |
                      U
          bat,
      tests divers
        exemples trace
          show_trace :-
            this comment will be traced once
            this comment will be traced on call and backtrack
            in member
              L = [1, 2, 3]
                member (X, L )
                  echo X
                    write (X)
                      write (" is in ")
                        write (L)
                          nl
                  fail
      misc tests
        % alarmes
          testa(0).
          testa(N):-
            alarm(2, (write('hop '), write(N), nl, K is N-1, testa(K)), Foobar).
        listes
          enlever X de L pour avoir une liste
            DEF_IO enlever, (+X,+L, -Reste)
              in
                X, []
                  []
                    out
                X, X .. L
                  L
                    out
                  !
                    goals
                X, Y .. L
                  Y .. L2
                    out
                  enlever (X, L, L2)
                    goals
        compteurs
          compteur (0,0):-!.
          compteur (N,N):- N > 0.
          compteur (N,K):- N1 is N-1, liste_range(N1, K).
          compte (N):- compteur (N, K)
        control structures
          dans ([X | L] , X, L).
          dans ([X | L] , U, R) :-
            dans (L, U, R)
          tests
            t1 :-
              dans ([1, 2, 3] , X, R)
                write (X)
                  nl
                    fail
            t2 :-
              ALL
                L = [1, 2, 3]
                  echo L
                dans (L , X, R)
                  write (X)
                    write (R)
                      nl
                  echo dans (X, R)
            t3 :-
              L = [1, 2, 3]
                echo L
              ALL
                iteritems (L, K, N)
                  echo iter (K, N)
      IO
        tests de fonctions de fichiers
          le cwd
            :- working_directory(X, X).
            :- working_directory(X,X),directory_files(X, Y), write (Y).
            show_cwd :-
              working_directory(X, X)
                write (X)
          test_write :-
            show_cwd
            open('output.txt',write,Out)
            write(Out,'Age("Peter",30)')
              write (Out, 'foobar is the top')
                nl(Out)
                  write(Out,'Skin("Smith","Black").' )
            close(Out)
          test_read :-
            open('output.txt', read, In)
            repeat
              read_line_to_codes(In,X)
                IF X=end_of_file
                  !
                    close (In)
                  writef(" ")
                    writef(X)
                      nl
          les lignes d'un fichier
            read_lines (File, Lines) :-
              open(File, read, In)
                read_lines_1 (In, Lines)
                close (In)
            read_lines_1 (In, [X | Lines] ) :-
              read_line_to_codes(In,X)
                writef(X)
                  nl
                IF X=end_of_file
                  fail
                  !
                    read_lines_1 (In, Lines )
            read_lines_1 (In, [] )
      tests pour swi prolog
        pour les DCG
          DCG
            sentence --> noun_phrase, verb_phrase.
            noun_phrase --> det, noun.
            verb_phrase --> verb, noun_phrase.
            det --> [the].
            det --> [a].
            noun --> [cat].
            noun --> [bat].
            verb --> [eats].
          integer (I) :-
            digit(D0)
            digits(D)
            {
              number_codes(I, [D0|D])
          integer (I) -->
            digit_2(D0)
            digits(D)
            {
              number_codes(I, [D0|D])
        alarmes
          testa :-
            alarm (10, write ('hop'), 1)
      Example by L CHAUDRON
        structure
          understatement
            ohoh
              yes
                vire
                  inverse
                    inv
        Expected result
        understatement :-
          ohoh(L),
          yes(L).
        ohoh([oh, please, dont, kiss, me])
        YES
          yes([]) :- print("!").
          yes(L) :-
            print(L),print("!"), nl,
            vire(L,M),
              yes(M).
        auxiliary functions for list manipulation
          vire(L,M) :-
            inverse(L,[_|Y]),
            inverse(Y,M).
          get a reversed member
            inverse(X,Y) :-
              inv(X,[],Y)
            inv
              inv([], L, L).
              inv([X|Y], L, R) :- inv(Y, [X|L], R).
    animations graphiques simples avec XPCE
      GOSUB XPCE
    QUEENS
      GOSUB
        placer n reines sur un échiquier de taille N
    PROBLEME DES CUBES
      GOSUB
    PROBLEME DU KNAPSACK
      GOSUB
        le probleme du Knapsack consiste à mettre une maximum d'objets de taille différente dans un sac de taille finie.
    test génération de fichiers auxiliaires
      GOSUB
  ici
    PROLOG.bat
  ici