[erlang-questions] Testing for improper list

黃耀賢 (Yau-Hsien Huang) g9414002.pccu.edu.tw@REDACTED
Mon Jul 16 16:17:14 CEST 2018


Yes, Richard, I gave the name because of language issue that I made the
is_improper_list/1 working but not be aware of its literal meaning, when I
reconsidered Guilherme's code.

The reason to consider a built-in may be that it won't work when applying
length/1 to a value [a|b], getting a bad_arg error. And is_list/1 does not
determine whether a value is an improper list.

Then there shell be an augmented version of is_list/1, that ...

is_improper_list([]) -> false;
is_improper_list([_|Value]) -> is_improper_list(Value);
is_improper_list(_) -> true.

Though the good use is to avoid writing some code to put any improper list
to your system.


On Mon, Jul 16, 2018 at 8:51 PM, Richard O'Keefe <raoknz@REDACTED> wrote:

> It is not entirely clear what you mean by
> an improper list.  Presumably [a|b] is an
> improper list, but is b all by itself an
> improper list, or what?
>
> I'd be tempted to go with
> is_not_a_proper_list(X) when length(X) >= 0 -> false;
> is_not_a_proper_list(_) -> true.
> but more importantly,
>
> - why do you want a built-in (as opposed to a library
>   function)?
> - why do you want this at all?
>
>
>
> On 16 July 2018 at 14:37, 黃耀賢 (Yau-Hsien Huang) <
> g9414002.pccu.edu.tw@REDACTED> wrote:
>
>> As off topic, the is_improper_list/1 may be rewritten to ...
>>
>> is_improper_list([_|Value]) -> is_improper_list(Value);
>>
>> On Mon, Jul 16, 2018 at 8:17 AM, Guilherme Andrade <g@REDACTED>
>> wrote:
>>
>>> Hello Karlo,
>>>
>>> On 16 July 2018 at 01:07, Karlo Kuna <kuna.prime@REDACTED> wrote:
>>>
>>>> Is there any built in method of checking if list is improper?
>>>>
>>>
>>> Something like this should do:
>>>
>>> > is_improper_list(Value) when length(Value) >= 0
>>> ->
>>>
>>>
>>> >     false;
>>>
>>>
>>>
>>> > is_improper_list(Value) ->
>>>
>>>
>>>
>>> >     is_list(Value).
>>>
>>> `length/1' will fail upon Value being an improper list.
>>>
>>> --
>>> Guilherme
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
>>
>> --
>>
>> Best Regards.
>>
>> --- Y-H. H.
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>


-- 

Best Regards.

--- Y-H. H.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180716/7b2ecf72/attachment.htm>


More information about the erlang-questions mailing list