Skip to content

data flow: copy/rot deeper into stack [a-la bi, dip combinators] #15

@cben

Description

@cben

not for now, just an annoyance to motivate some thinking...

Example you can't achieve now:

  • Build up a complex value e.g. a rainbow
    • save a copy somewhere...
      • split it into R, G, B components
    • ...do something else with the other copy e.g. reverse
      [at this point, if you copy-ed before, it's buried under 3 values; swap can't reach that deep either

In Forth, the solutions are (1) words like rot, over etc. that reach deeper than swap (2) temporary save copy on return stack dup >r, later restore r> (3) named [local] variables.

I find (1) too low-level, I'd rather want something with expressive power similar to (2).

I don't want to do quatations and combinators, but Factor's bi and dip combinators would express it nicely:
[ split ] [ reverse ] bi or [ split ] keep reverse
What's great is the you see the overall data flow without having to care how many results [ split ] produces.

🤔 I think I'll go with something like "pack" multiple values into one and later "unpack"?
No higher-order combinator, yes aggregate data (that's still simulatneously visible).

  • Possibly could even express (1) via "pack whole stack", arbitrary transform, "unpack whole stack"?

  • xy language goes all-in on whole-(stack, continuation) manipulations, and in particular has "cache" / "uncache" primitives which save things at end of continuation. dup => split <= reverse. Hmm, this is not unlike >r and r>?

  • I don't want a second "return stack" but could achive similar results with single stack "rotate to bottom of stack", "rotate from bottom of stack"? I don't know if I like it; I don't think it's sufficient for other needs(?)...
    Need to think of more interesting data flow cases and "node & wire diagrams"... 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions