Support proper cons cells (dotted pairs) #60

Open
opened 2026-02-07 17:11:24 +00:00 by navicore · 0 comments
navicore commented 2026-02-07 17:11:24 +00:00 (Migrated from github.com)

Summary

Relax the cons constraint to allow any value as the second argument, enabling proper dotted pairs and improper lists.

Motivation

Currently seq-lisp's cons requires a list as the second argument. This is non-standard — in Scheme/Common Lisp, (cons 1 2) produces the dotted pair (1 . 2).

We hit this exact limitation during the document symbols LSP work, where (cons #f pos) failed because pos is a number. We had to use list as a workaround.

seq-lisp-2 implements this correctly with SCons { car, cdr } where cdr can be any value.

Scope

  • Update cons in src/eval.seq to accept any value as second argument
  • Add dotted pair display support to the printer ((1 . 2))
  • Add dotted pair syntax to the reader/parser
  • Update car/cdr to work on dotted pairs
  • Ensure list operations (map, filter, length, etc.) handle improper lists gracefully
  • Add tests for dotted pairs

Notes

This makes the Lisp more standard and eliminates a class of surprising runtime errors.

Inspired by seq-lisp-2/src/types.seq SCons type.

## Summary Relax the `cons` constraint to allow any value as the second argument, enabling proper dotted pairs and improper lists. ## Motivation Currently seq-lisp's `cons` requires a list as the second argument. This is non-standard — in Scheme/Common Lisp, `(cons 1 2)` produces the dotted pair `(1 . 2)`. We hit this exact limitation during the document symbols LSP work, where `(cons #f pos)` failed because `pos` is a number. We had to use `list` as a workaround. seq-lisp-2 implements this correctly with `SCons { car, cdr }` where `cdr` can be any value. ## Scope - Update `cons` in `src/eval.seq` to accept any value as second argument - Add dotted pair display support to the printer (`(1 . 2)`) - Add dotted pair syntax to the reader/parser - Update `car`/`cdr` to work on dotted pairs - Ensure list operations (`map`, `filter`, `length`, etc.) handle improper lists gracefully - Add tests for dotted pairs ## Notes This makes the Lisp more standard and eliminates a class of surprising runtime errors. Inspired by `seq-lisp-2/src/types.seq` `SCons` type.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
navicore/seq-lisp#60
No description provided.