Skip to content
This repository was archived by the owner on Sep 9, 2019. It is now read-only.
This repository was archived by the owner on Sep 9, 2019. It is now read-only.

RFC: make empty list the identity of cons #24

@hellerve

Description

@hellerve

cons is the zepto function to append something to the start of a list. It is quite useful for working with lists, even though the behavior of zepto's implementation of this function differs from the standard Scheme implementation.

A few motivating examples of how cons currently works:

(cons 1 [2]) ; [1 2]
(cons [3] [4]) ; [[3] 4]
(cons 1 (cons 2)) ; pair[1, 2]
(cons 1) ; pair[1]

Ass you see, its normal type is a dotted list, but it will also work with regular lists. Well, that's nice already, isn't it? But what if we call it without an argument?

(cons) ; explosion!

It will fail! But wait, we just said it has a type associated with it! Wouldn't it make sense to return an empty dotted list then? Well... yes. The only problem with that is that dotted lists cannot be empty. They require at least one element to exist.

Hum... But, what if we do the next best thing then and just return an empty list? That violates the whole "its type is a dotted list" invariant, but it is really muddy to begin with and dotted lists should only be worked with if you really have to (i.e. in really fancy macros).

So, what this RFC proposes is the following behavior:

(cons) ; []

I hope that makes sense!
Cheers

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions