Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Very simple anonymous lambda generator in Rebol
>> 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"
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