defmoduleMaindodefaspellClearHeaderdoreceivedo_->:okendenddefaspellGetCorrections(lst\\[])doreceivedo{_,{:data,{:eol,msg}}}->casemsgdo""->Enum.reverse(lst)_->aspellGetCorrections([msg|lst])endendenddefaspellLoop(pt)doreceivedo{pid,{:correct,msg}}->Port.command(pt,msg)send(pid,{:correct,aspellGetCorrections})aspellLoop(pt)endenddefaspellStartAppdo#This is the part of the code I'm interested inpt=Port.open({:spawn_executable,System.find_executable("aspell")},[:binary,{:args,["-a"]},{:line,1024}])Port.connect(pt,self())aspellLoop(pt)#This is the part of the code I'm interested inenddefaspellFilterErrors(lst)doStream.filter(lst,fne->String.first(e)!="@"end)|>Enum.filter(fne->String.first(e)!="*"end)enddefmain()dopid=spawn(Main,:aspellStartApp,[])send(pid,{self(),{:correct,"Thwis is the message\n"}})receivedo{:correct,lst}->Enum.each(aspellFilterErrors(lst),fne->IO.putseend)endIO.puts"\n\n"send(pid,{self(),{:correct,"This the enpd, my only frieend the end.\n"}})receivedo{:correct,lst}->Enum.each(aspellFilterErrors(lst),fne->IO.putseend)endendend
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.