[erlang-questions] Suggestion for a spell corrector implementation
Federico Feroldi
pix@REDACTED
Tue May 15 12:49:51 CEST 2007
Joe Armstrong wrote:
> It's rather difficult to read your code - is it possible to indent the code
> so as to show the structure, and use shorter function names etc. this would make
> it much more readable
Hi Joe,
thanks for the suggestion, I've tried to indent the code to my tastes,
are there any style guidelines for the Erlang code? (such as GNU
intending style for C/C++ code)
> You could write deletions like this:
>
> deletions(Word) ->
> [Word -- [I] || I <- Word]
>
> -- is the list subtraction operator
As I understand this will only remove the 1st occurrence of each letter,
what I need in this case is to remove each position letter once.
6> W2 = "santa".
"santa"
7> [W2 -- [I] || I <- W2].
["anta","snta","sata","sana","snta"]
you got "snta" two times, the last one should be "sant".
> trans([H,H1|T], Before, L) ->
> trans([H1|T], [H|Before], [reverse(Before, [H1,H|After]) | L]
>
> The convention I use is to put the list I am "reducing" on the far left
> and call the variables [H|T] etc. the "result" is the last argument - it's
> a list (called L).
Thanks for the suggestion! I just user more "verbose" names to let
people unfamiliar with Erlang's syntax understand it better! :)
Do you believe I can implement the edits generator function with some
kind of list comprehension instead of using recursion?
thanks!
(sorry for the bad code, I've just started to learn Erlang!)
-federico
http://www.pixzone.com/blog/
More information about the erlang-questions
mailing list