Last active
September 6, 2018 09:38
-
-
Save draegtun/11b0258377a3b49bfd9dc91c3a1c8c3d to your computer and use it in GitHub Desktop.
Very simple anonymous lambda generator in Rebol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> double: lambda [? * 2] | |
>> double 2 | |
== 4 | |
>> double: lambda [? + ?] | |
>> double 4 | |
== 8 | |
>> add2: lambda [?1 + ?2] | |
>> add2 2 4 | |
== 6 | |
>> add3: lambda [?a + ?b + ?c] | |
>> add3 1 2 4 | |
== 7 | |
>> invalid-func: lambda [? + ?1] | |
** User error: "cannot match ? with ?name placeholders" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rebol [ | |
title: {Very simple anonymous lambda generator} | |
] | |
lambda: function [block] [ | |
spec: make block! 0 | |
parse block [ | |
any [ | |
set word word! (if #"?" == first to-string word [append spec word]) | |
| skip | |
] | |
] | |
spec: unique sort spec | |
if all [ | |
(length? spec) > 1 | |
found? find spec '? | |
][do make error! {cannot match ? with ?name placeholders}] | |
func spec block | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment