Skip to content

Instantly share code, notes, and snippets.

@draegtun
Last active September 6, 2018 09:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save draegtun/11b0258377a3b49bfd9dc91c3a1c8c3d to your computer and use it in GitHub Desktop.
Save draegtun/11b0258377a3b49bfd9dc91c3a1c8c3d to your computer and use it in GitHub Desktop.
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