[eeps] EEP 31

Patrik Nyblom pan@REDACTED
Fri Dec 11 07:47:04 CET 2009


Hi Fredrik and all readers of the eeps list!

Adding guards is generally a "bigger step" than adding stdlib modules, but 
you definitely have a point.

Actually I'm more for allowing matching in guards, eliminating the need 
for special guard bif's doing the job a simple match could do. The 
variable scope is of course a problem (not as easilly solved as one might 
think), and the idea has been discussed on erlang-questions. That is far 
beyond the scope of this EEP though.

Also guards in other modules than erlang is new to the language, maybe 
erlang:binary_part (or auto-imported as binary_part) could be added, but 
adding autoimports will not be done between releases (and not until we'we 
straighted out the rules for shadowing autoimports with local functions). 
I'll add the suggestion to the EEP, but the initial implementation might 
lack the guard bif.

The diff funtion is nice! I preferr the simple variant which returns the 
length of the prefix. The tuple is so easilly built if you have the length 
(=> the index). I suppose the list of binaries should be of variable 
length too, why a tuple is not an ideal return value. I'll add 
longest_common_{prefix/suffix} to the EEP. (I think those names are good, 
although a little long - the functionality is not too common though, so a 
longer name might be acceptable).

To summarize:
- I'll add a suggestion about allowing part/3 in guards (possibly with a 
different name)
- I'll add longest_common_prefix/1 -> int() and longest_common_suffix/1 -> 
int() (both returning the *length* of the prefix/suffix).

Cheers,
/Patrik

On Thu, 10 Dec 2009, Fredrik Svahn wrote:

> Hi,
>
> Is there any chance of allowing part/[2,3] to be used as a guard? For tuples
> there is already element/2. Something like the following would be very
> useful:
>
> my_func(Pos, Bin, Pattern) when binary:part(Bin, Pos, size(Pattern)) ==
> Pattern ->
>    ...
>
> Another nice to have would be a diff function returning either the first
> position where a list of binaries differ, or a tuple with the common
> beginning and the differing ends of the binaries, e.g.
>
> binary:diff([<<"abcde">>, <<"abcdghie">>]) -> 4, or
> binary:diff([<<"abcde">>, <<"abcdghie">>]) -> {<<"abcd">>, <<"e">>,
> <<"ghie">>}
>
> The name diff might be somewhat misleading, maybe
> longest_common_prefix/suffix is more descriptive (borrowed from Joe
> Armstrongs elib_misc)?
>
> BR /Fredrik
>
>
>
>
> On Thu, Nov 26, 2009 at 3:25 PM, Patrik Nyblom <pan@REDACTED> wrote:
>
>> A new EEP is submitted.
>>
>> EEP 31 is a slight rework of a part of EEP 9.
>>
>> Comments on this EEP are accepted until 10-Dec-2009. Please send all
>> comments and suggestions to this mailing list (eeps@REDACTED).
>>
>> Best regards,
>>
>> /The OTP team/Patrik
>>
>> ________________________________________________________________
>> eeps mailing list. See http://www.erlang.org/faq.html
>> eeps (at) erlang.org
>>
>>
>


More information about the eeps mailing list