Skip to content

Instantly share code, notes, and snippets.

@maximvl
Created May 15, 2017 21:51
Show Gist options
  • Save maximvl/d952c313a8f08cf011a9af965f7f3ec0 to your computer and use it in GitHub Desktop.
Save maximvl/d952c313a8f08cf011a9af965f7f3ec0 to your computer and use it in GitHub Desktop.
quick funcs
Red [
author: {Maxim Velesyuk}
description: {
Quick in-place function definitions without explicit arguments specification.
`_` is next arugment, `_N` is N-th argument
}
]
inc: func ['word] [set word 1 + get word]
qf: function [body] [
args: copy []
counter: 1
max-n: 0
rule: [
any [
pos: '_ (
pos/1: to-word rejoin ["_" counter]
append args pos/1
inc counter
) |
pos: word!
if (#"_" = first s: to-string pos/1) (
arg-n: to-integer next s
max-n: max max-n arg-n
) |
into rule |
skip
]
]
parse body rule
if counter < max-n [
repeat c max-n - (counter - 1) [
append args to-word rejoin ["_" counter]
inc counter
]
]
func args body
]
f: qf [ reduce [_ _] ]
probe f 1 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment