Skip to content

Add array_fold builtin function - #145

Merged
apoelstra merged 1 commit into
BlockstreamResearch:masterfrom
m-kus:feat/array-fold-macro
Sep 25, 2025
Merged

apoelstra merged 1 commit into
BlockstreamResearch:masterfrom
m-kus:feat/array-fold-macro

Conversation

@m-kus

@m-kus m-kus commented Sep 22, 2025

Copy link
Copy Markdown

This PR adds array_fold similar to list folding, but for arbitrary array length.
Also added relevant section to the book, and VSCode syntax.

@m-kus
m-kus force-pushed the feat/array-fold-macro branch from fbf5615 to e95bd7d Compare September 22, 2025 22:59
@uncomputable

Copy link
Copy Markdown
Contributor

Macros are compile-time snippets that expand into efficient Simplicity code, provifing a clean simple interface.

You are describing a builtin function, not a macro. A SimplicityHL macro is a notation that expands to SimplicityHL code, not to Simplicity code. list_fold is defined for arbitrary list lengths and it is also a builtin function. (These functions support a kind of generics that normal SimplicityHL functions don't support, but that doesn't matter.)

At this point in time, I think it's not desirable to add macros to SimplicityHL. They make it harder to reason about the code. Let's refactor the PR to clarify that array_fold is a builtin function.

@m-kus
m-kus force-pushed the feat/array-fold-macro branch from e95bd7d to 8c4fd1b Compare September 23, 2025 22:30
@m-kus m-kus changed the title Add array_fold macro Add array_fold builtin function Sep 23, 2025

@uncomputable uncomputable left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 8c4fd1b Looks good to me, but canndrew or apoelstra should also review this

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 8c4fd1b; successfully ran local tests

@apoelstra
apoelstra merged commit 7ec4063 into BlockstreamResearch:master Sep 25, 2025
9 checks passed
@m-kus
m-kus deleted the feat/array-fold-macro branch September 26, 2025 09:32
apoelstra added a commit to apoelstra/s-lang that referenced this pull request Oct 31, 2025
This module was introduced in BlockstreamResearch#145 as a public module. But actually it is
only ever used by the compiler, and it doesn't really make sense outside
the compile because of its use of `ProgNode`.

We may want to later make the builtins module be an extension trait of
Constructible or something, but as long as it depends on ProgNode it
should not be public (and it cannot be public, after the next commit).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants