Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. % hello world program
  2. -module(helloworld).
  3. -export([start/0]).
  4. -export([odwrocenieDzialania/1]).
  5. -export([wczytajCiagDoListy/1]).
  6. -export([czyJestNaLiscie/2]).
  7. -export([pobierzElementZListy/2]).
  8. -import(lists,[reverse/1]).
  9. -import(lists,[foreach/2]).
  10. -import(lists,[nth/2]).
  11. -import(lists,[member/2]).
  12.  
  13. start() ->
  14. %wczytanie ciągu
  15. Ciag=wczytajCiagDoListy("a + b"),
  16. %odwrócenie kolejności w ciągu
  17. OdwroconyCiag=odwrocenieDzialania(Ciag),
  18. io:fwrite("~p~n",[OdwroconyCiag]),
  19. %utworzenie listy operatorów + - * /
  20. Operatory=["+","-","*","/"],
  21. %pobranie Elementu z listy i sprawdzenie czy jest Operatorem
  22. %Jeśli jest operatorem to dodaj na Stos, jeżeli nie dodaj
  23. %do ciągu wyjściowego
  24.  
  25. foreach(fun(X) ->
  26. io:format("~p~n",[X]),
  27. V1=czyJestNaLiscie(X,Operatory),
  28. io:format("~p~n",[V1]),
  29. Stos=[1,2],
  30. if
  31. V1 == true ->
  32. Stos=X;
  33. true->
  34. CiagWyjsciowy=[X]
  35. end
  36.  
  37. end, OdwroconyCiag),
  38.  
  39. io:fwrite("~p~n",[Stos])
  40. .
  41.  
  42. wczytajCiagDoListy(Ciag)->
  43. Lista=string:tokens(Ciag, " "),
  44. Lista.
  45.  
  46. odwrocenieDzialania(L) ->
  47. reverse(L).
  48.  
  49. pobierzElementZListy(POZYCJA,LISTA) ->
  50. nth(POZYCJA,LISTA).
  51.  
  52.  
  53. czyJestNaLiscie(CO,GDZIE) ->
  54. member(CO,GDZIE).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement