[erlang-questions] Coloring variable bindings to lessen ambiguity.

Henri Tuhola henri.tuhola@REDACTED
Thu Nov 16 11:34:55 CET 2006


Hi.

I noticed that it causes very odd consequences if you mistakenly
interpret variable occurrence to variable binding, like. Lets take this
kind of part:
    receive {Port, {data, Data}} -> ok end.

You know what Data -variable does here? Right. Now lets add some more:
    Port ! {self(), {command, Data},
    receive {Port, {data, Data}} -> ok end.

You notice that your earlier line changes it's meaning in really fast
pace. The code is ambiguous for human reader.

There are few ways to solve this problem, I think that coloring the
first occurrence of variable in scope by color editor would solve it all
without any changes into the language!

ie: first, when it'd be alone like this:
    fn(Port) -> 
        receive {Port, {data, Data}} -> ok end.

Would cause the occurence of 'Data' on the second line to be
colorised, thus 'Port' on the first line.

Now when you'd add this:
    fn(Port) ->
        Data = 23, receive {Port, {data, Data}} -> ok end.

'Data' right after the first arrow would be coloured and the latter
variable would be white. 

Benefit is that you'd clearly see whether Data is referenced or bound!

It'd require the text editor to understand the language scope, how hard
this can be?

T: Henri Tuhola.



More information about the erlang-questions mailing list