Universal Lambda Machine: Difference between revisions
Content deleted Content added
m →{{header|Perl}}: fixed syntax |
Add bruijn |
||
Line 94: | Line 94: | ||
7bb03 91a1a |
7bb03 91a1a |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Bruijn}}== |
|||
We use bruijn's meta encoding and its [https://text.marvinborner.de/2023-09-03-21.html self-interpreter]. |
|||
<syntaxhighlight lang="bruijn"> |
|||
:import std/Combinator . |
|||
:import std/Number/Binary . |
|||
:import std/Meta . |
|||
:import std/List . |
|||
# converts string to list of bits |
|||
str→blc map (c ∘ lsb) |
|||
:test (str→blc "0010") ([[1]] : ([[1]] : ([[0]] : {}[[1]]))) |
|||
# converts list of bits to string |
|||
blc→str map [0 '0' '1'] |
|||
:test (blc→str ([[1]] : ([[1]] : ([[0]] : {}[[1]])))) ("0010") |
|||
# reduces BLC string to BLC string |
|||
main str→blc → blc→meta → β* → meta→blc → blc→str |
|||
:test (main "0010") ("0010") |
|||
</syntaxhighlight> |
|||
To reduce the given examples efficiently, you currently have to use the ION reducer and, for infinite output, specifically take only the first n elements of the output list, as results are not always streamed lazily. |
|||
=={{header|C}}== |
=={{header|C}}== |