Created
March 9, 2022 09:21
-
-
Save mrsolarius/1fbad495779f5c6fc1c68d65575c5f9e to your computer and use it in GitHub Desktop.
Comment verifier que un ellement apartien à une liste en erlang ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Spéc et implementation d'une fonction d'appartenance d'un élément à une liste | |
% app(E,L) renvoie vrai si E appartient à L | |
% | |
% app(X,L) vrai ssi X appartient à L | |
% | |
% Exemple : | |
% app(1,[1,2,3,4]) = true | |
% app(5,[1,2,3,4]) = false | |
% Analyse sur L : 2 cas | |
% 1) L = [] | |
app(_,[])->false; | |
% 2) L /= [] : L = [Pr|Fin] | |
% a) X = Pr : vrai | |
app(X,[X|_])->true; | |
% b) X /Pr | |
app(X,[Pr|Fin]) when X=/=Pr -> app(X,Fin). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment