Last active
April 27, 2019 06:02
-
-
Save toomasv/58451e09cb7efa9b3e2bed93484a7ae2 to your computer and use it in GitHub Desktop.
Funny `of` op!
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
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