petits tests
tests divers
  **module** lang = pl
    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.
        quelques personnes
          Pierre Caboche
          Joel Foutelet
          Eric de la Clergerie
            INRIA
    notation
      ' (' ::= '('
      ' [' ::= '['
    infos de base
      bar.
      bat
      bat ('écho').
      baz.
      baz (1,2,_,_,_,_)
      foo (_)
      x
      y
      z
      t
      u
      v (_, _)
    spe :-
      bar,,
      baz
      bat,
    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,
    pour les DCG
      integer (I) :-
        digit(D0)
        digits(D)
        {
          number_codes(I, [D0|D])
      integer (I) -->
        digit_2(D0)
        digits(D)
        {
          number_codes(I, [D0|D])
    essai animation
      :-use_module(library(pce)).
      sm:-
        %run this
        %runs animation over 600 pixels, 4 seconds long, with 40 FPS
          sm_a(600,4,40).
      notation
        CHK ::=
          %check is {a1} exists; if it does, delete it
            (object( @{a1}), !, free( @{a1}); true)
        ::=
          write("{a0}")
            nl
          {L}
        ::=
          % {a0}
          write("... >>> {a0}")
            nl
          {L}
          nl
      sm_a (Length,Duration,FPS):-
        CREATE OBJECTS
          %check is window exists; if it does, delete it
            (object( @window),!,free(@window);true)
          %check is floor exists; if it does, delete it
            (object( @floor), !, free( @floor); true)
          %%check if box exists; if it does, delete it
            (object( @box), !, free( @box); true)
          %%check if timer exists; if it does, delete it
            (object( @my_timer), !, free( @my_timer); true)
          CHK window
          CHK floor
          CHK box
          CHK timer
          %create window
            new( @window,picture('Window',size(900,500)))
            %display window
              send( @window,open)
            %make sure to use double-buffering
              send(@window,buffered_update,true)
          %create floor
            new( @floor,box(800,10))
            %colour floor
              send( @floor,fill_pattern,colour(green))
              send( @window,display,@floor,point(50,300)), %show floor
          %creates box
            new( @box,box(50,50))
            %colours box yellow
              send( @box,fill_pattern,colour(yellow))
          creation ok
        ANIMATION
          parameters for animation
            animation
              %how many frames are to be drawn
                Frames is Duration*FPS
              %what's the distance between steps
                Step is Length/Frames
              %what is the delay between steps
                Delay is 1/FPS
          %shows Object
            send( @window,display,@box,point(50,100))
            send( @window,flush)
          simple animation
            ani(Step,Delay,Frames,point(50,20)).
            anime(Step, 0.05, What, 1000)
      animation de base
        ani(Step,Delay,Frames,point(X,Y)) :-
          %moves box to the right
            write('moves box')
            send( @box,x(X+Step))
          %flushes
            write('flushes')
            send( @window,flush)
          new(@my_timer, my_timer(Step, Delay, Frames, X)).
      animation LG
        anime(Step, Delay, What, 0):-
          !
            fail
        anime(Step, Delay, What, K):-
          % moves box
            write('moves box')
            send( @box,x(50+Step*K))
          %flushes,
            write('flushes')
            send( @window,flush)
          % delai
            write ('.....>')
              write (K)
                nl
            alarm(Delay, (K2 is K -1, anime(Step, Delay, What, K2)), Foo)
            write ('<...')
              write (K)
                nl
      :- pce_begin_class(my_timer, object).
      some constants
        variable(mytimer, timer, both, "timer lançant l'animation fréquence 20 fois par seconde").
        variable(step, number, both, "delta x").
        variable(frames, number, both, "number of moves").
        variable(posX, number, both, "xpos of the box").
    alarmes
      testa :-
        alarm (10, write ('hop'), 1)
    misc tests
      % alarmes
        testa(0).
        testa(N):-
          alarm(2, (write('hop '), write(N), nl, K is N-1, testa(K)), Foobar).
      compteurs
        range(0,0):-!.
        range(N,N):- N > 0.
        range(N,K):- N1 is N-1, range(N1, K).
        compte(N):-range(N, K).
      IO
        tests de fonctions
          :- working_directory(X, X).
          :- working_directory(X,X),directory_files(X, Y), write (Y).
          show_cwd :-
            working_directory(X, X)
              write (X)
          test_open :-
            show_cwd
            open('output.txt',write,Out)
            write(Out,'Age("Peter",30)')
              nl(Out)
                write(Out,'Skin("Smith","Black").' )
            close(Out)
          test_read :-
            open('output.txt', read, In)
            repeat
              read_line_to_codes(In,X)
                writef(" ")
                  writef(X)
                    nl
              X=end_of_file
                !
                  close (In)
  ici
    PROLOG.bat