Convert while/until/times combinators to recursive style #51
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
seq-lisp-2-backport
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/seq-lisp#51
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?
Background
The Seq language currently has
while,until, andtimescombinators that require neutral stack effects. This creates false expectations for users who expect these to work like loops in other languages - you can't accumulate results on the stack or exit based on runtime criteria.Problem
Proposal
while,until,timesGoal
Gather real data on what patterns emerge when forced to use recursion. This will inform whether/how to add iteration combinators back to Seq with correct semantics.
Related
This is part of Seq language design cleanup - making changes before external users depend on current behavior.
❯ can you point me to an example of the -loop pattern?
⏺ Read(src/eval.seq)
⎿ Read 20 lines
⏺ Here's a simple one - list-length at src/eval.seq:250-258:
: list-length ( SexprList -- Int )
0 swap list-length-loop ; # Setup: put accumulator (0) under the list
: list-length-loop ( Int SexprList -- Int )
dup snil? if
drop # Empty list? Drop it, return accumulator
else
scdr swap 1 i.add swap # Get rest, increment acc, swap back
list-length-loop # Tail recurse
then ;
Here's one that builds a result - append-loop at src/eval.seq:3008-3018:
⏺ Read(src/eval.seq)
⎿ Read 20 lines
⏺ : append-lists ( SexprList SexprList -- SexprList )
swap list-reverse swap append-loop ;
: append-loop ( SexprList SexprList -- SexprList )
over snil? if
nip # List1 empty - return List2
else
over scar swap scons # Prepend car of List1 to List2
swap scdr swap # Move to rest of List1
append-loop # Tail recurse
then ;