Built-in list type has no literal-construction syntax — discussion #461
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#461
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Seq's built-in
listtype has no literal-construction syntax.Today the only way to put values into a
list(that I'm aware of)is to go through
string.split:For non-string element types or for ad-hoc test data, that's not
an option. This issue isn't a proposal — it's a problem statement
and a sketch of options, in case the topic is on the roadmap or
worth a side conversation.
Where the gap shows up
exercises/15-lists/01-basics.seqin seqlings. The exerciseintroduces the
listtype but has to construct every test listwith
string.split, which couples list-of-strings teaching tostring parsing.
exercises/38-cons-list/in seqlings (this one I just wroteto teach ADTs from variant primitives). Every test reads
empty 3 swap prepend 2 swap prepend 1 swap prependto build athree-element list. That's instructive once, but obscures the
test that follows.
patch-seq/examples/data/cons-list.seq— your own canonicalexample does the same
nil 3 swap cons 2 swap cons 1 swap consdance for the demo list. It's idiomatic and clear once you read
it, but it's also the same six tokens for every literal.
Sketch of options (not a proposal)
I don't have a strong opinion on which is right; flagging the
constraints I'm aware of so the conversation has a starting point.
{ 1 2 3 }— Factor-style.fixed-element or growable list is a separate decision.
[ 1 2 3 ] >list— quotation-to-list conversion.a runtime word that walks the quotation and pushes its
results into a list.
known stack effect
( -- T T T … ).3 [ 1 2 3 ] make-list— explicit length + quotation.makepattern.
compiler can already see in the quotation.
Stack-tagged form:
1 2 3 3 >list.swap prependladder for anything past three or fourelements.
#( 1 2 3 )or another paren-prefixed form.( ... )is reserved for stack effect comments, so aprefix sigil is needed.
Why I didn't just file a PR
The shape of "what's a list literal in a stack language?" is more
about taste than mechanics, and conflating list literals with
quotations (option 2) versus introducing a new sigil (options 1
and 5) versus going purely word-level (options 3 and 4) is a
direction call I'd want you to make.
If you'd rather close this and discuss in another forum, that's
fine — happy to follow wherever the conversation lives.
Where I hit it
Building the
38-cons-listchapter for seqlings, where thetest-data ladder dominated several otherwise-clean exercises.
#465