[erlang-questions] "Symmetrical" function

Richard O'Keefe ok@REDACTED
Wed Feb 18 00:05:06 CET 2009


On 17 Feb 2009, at 7:13 pm, Michael Radford wrote:
>> 	oi([X|Xs], [Y|Ys]) ->
>> 	    if X < Y -> oi(Xs, [Y|Ys])
>> 	     ; X > Y -> oi([X|Xs], Ys)
>> 	     ; true  -> oi(Xs, Ys)
>> 	    end;
>> 	oi(_, _) ->
>> 	    [].
>>
>> Here #A is infinite, the number of clauses is 2, and I don't see
>> any good way to write half of f.
>
> I think you can write just the diagonal...
>
> oi(_, _) -> [].


Yeah, thinko there.  Change that to

oi([X|Xs], [Y|Ys]) ->
     if X < Y -> oi(Xs, [Y|Ys])
      ; X > Y -> oi([X|Xs], Ys)
      ; true  -> [X|oi(Xs, Ys)] % the mistake was here
     end;
oi(_, _) ->
     [].

The substantive point remains.  I don't see any good way
to write half of <the function I *meant* to write>.




More information about the erlang-questions mailing list