[erlang-questions] Testing for improper list

Karlo Kuna <>
Mon Jul 16 18:51:22 CEST 2018


i have solution just as Yau-Hsien suggested but i was wandering is there
highly optimized version (bif of nif) of this.
sure one can easily do NIF but i think is_improper_list/1 or
is_proper_list/1 should be in standard library.

improper list is pretty clear term in erlang documentation.

also why i want this: suppose i want type ob object to be list but i also
want some sort of additional information for it,
then syntax [...|some_type_or_property] seems elegant.
Alternatives are

   - {some_type_or_property, List}
   - parse transformations
   - record or map

however as i need/want this as input to file:consult parse transformations
are difficult here and object wrappers as
tuple, map or record are to verbose and noisy




On Mon, Jul 16, 2018 at 4:17 PM 黃耀賢 (Yau-Hsien Huang) <
> wrote:

> 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 <> 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) <
>> > 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 <>
>>> wrote:
>>>
>>>> Hello Karlo,
>>>>
>>>> On 16 July 2018 at 01:07, Karlo Kuna <> 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
>>>> 
>>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>>
>>>>
>>>
>>>
>>> --
>>>
>>> Best Regards.
>>>
>>> --- Y-H. H.
>>>
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> 
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
>
>
> --
>
> Best Regards.
>
> --- Y-H. H.
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180716/4169959b/attachment.html>


More information about the erlang-questions mailing list