Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 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=[],
  30. if
  31. V1 == 1 ->
  32. Stos=X;
  33. true->
  34. CiagWyjsciowy=[X]
  35. end,
  36. io:fwrite("~p~n",[Stos])
  37. end, OdwroconyCiag)
  38. .
  39.  
  40. wczytajCiagDoListy(Ciag)->
  41. Lista=string:tokens(Ciag, " "),
  42. Lista.
  43.  
  44. odwrocenieDzialania(L) ->
  45. reverse(L).
  46.  
  47. pobierzElementZListy(POZYCJA,LISTA) ->
  48. nth(POZYCJA,LISTA).
  49.  
  50.  
  51. czyJestNaLiscie(CO,GDZIE) ->
  52. member(CO,GDZIE).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement