[erlang-questions] Suggestion for a spell corrector implementation

Joe Armstrong erlang@REDACTED
Tue May 15 12:18:28 CEST 2007


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

...

 You could write deletions like this:

deletions(Word) ->
    [Word -- [I] || I <- Word]

-- is the list subtraction operator

The 3'rd clause of transposition_edits is a mess

Change

transposition_edits(Before, [Current, Next | After], Edits) ->
    transposition_edits([Current | Before],
			[Next | After],
			[ lists:reverse(Before) ++ [Next, Current] ++ After |
			  Edits]).


To:

transposition_edits(Before, [Current, Next | After], Edits) ->
    transposition_edits([Current | Before],
			[Next | After],
			reverse(Before, [Next, Current|After]) | Edits]).

I'd probably write it like this

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).

Whenever you see ++ think "can I get rid of this"

/Joe



On 5/14/07, Federico Feroldi <pix@REDACTED> wrote:
> Hello everybody,
> following the Spell Corrector implementation in 20 lines of Python code
> made by Peter Norvig (http://www.norvig.com/spell-correct.html) I wanted
> to try an Erlang one, here's what I did:
>
> http://www.pixzone.com/blog/223/spell-corrector-aka-google-suggest-in-erlang-first-part/
>
> It's a bit more that 20 lines of code but it can be probably refactored
> and optimized, I'm open to any suggestions on how to improve the code!
>
> thanks
>
> -federico
>
> http://www.pixzone.com/blog/
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list