Skip to content

Instantly share code, notes, and snippets.

@toomasv
Last active April 27, 2019 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toomasv/58451e09cb7efa9b3e2bed93484a7ae2 to your computer and use it in GitHub Desktop.
Save toomasv/58451e09cb7efa9b3e2bed93484a7ae2 to your computer and use it in GitHub Desktop.
Funny `of` op!
Red [
Date: 26-Apr-2019
Idea: [@nedzadarek @giesse]
Source: https://gitter.im/red/help?at=5cc295d3375bac747008989b
]
of: make op! function ['word 'value] [
either any [
attempt [out: reflect get value word]
attempt [out: reflect value word]
attempt [
rule: [collect any [keep _ | skip]]
put third rule 'keep to-word head change back tail to-string word #"!"
out: parse value rule
]
attempt [out: parse get value rule]
][out][
cause-error 'user 'message ["Bad arguments!"]
]
]
; Another version from @nedzadarek's https://gitter.im/red/help?at=5cc36f27990feb45180a53d7
comment [
of: make op! func [rule source] [
either any [object? :source map? :source any-function? :source] [
reflect :source rule
][
parse source [collect any [keep rule | skip]]
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment