word!
value to anything, it still points to a "default" value of type unset!
.
none!
value and say "point to none
but report it as an integer!
".
>> of: make op! func ['word value] [reflect get value word]
== make op! [['word value]]
>> words of system
== [version build words platform catalog state modules codecs schemes ports locale options script standard lexer console view reactivity]
@giesse It's a known bug.
Musings on of
:
of: make op! function ['word 'value] [
either any [
attempt [out: reflect get value word]
attempt [out: reflect value word]
attempt [
type!: get to-word head change back tail to-string word #"!"
out: parse value compose/deep [
collect any [keep (type!) | skip]
]
]
][out][
cause-error 'user 'message ["Bad arguments!"]
]
]
;== make op! [['word 'value /local out type!]]
words of system
;== [version build words platform catalog state modules codecs schemes ports locale ;options script standard lexer console view reactivity]
body of collect
;== [
; keep: func [v /only] [either only [append/only collected v] [append collected v] v]
; unless collected [collected: make block! 16]
; parse body rule: [
; ...
spec of find
;== [{Returns the series where a value is found, or NONE}
; series [series! bitset! typeset! any-object! map! none!]
; value [any-type!]
; /part "Limit the lengt...
values of #(a 1 b 2 c: 3.0)
;== [1 2 3.0]
words of [a 1 b 2 c: 3.0]
;== [a b]
set-words of [a 1 b 2 c: 3.0]
;== [c:]
integers of [a 1 b 2 c: 3.0]
;== [1 2]
spec of [a 1 b 2 c: 3.0]
;*** User Error: "Bad arguments!"
of: make op! function ['word 'value] [
either any [
attempt [out: reflect get value word]
attempt [out: reflect value word]
attempt [
type!: get to-word head change back tail to-string word #"!"
rule: compose/deep [collect any [keep (type!) | skip]]
out: parse value rule
]
attempt [out: parse get value rule]
][out][
cause-error 'user 'message ["Bad arguments!"]
]
]
'
) + of
+ value). I haven't made it safe nor implemented all X-of
. Yes, something like reflect
can be good - if reflect will add something, then it will be "automatically implemented". We can go deeper with other values, like @toomasv has done ( :clap: )
type!
so, for simplicity, I added another attempt
. We can add support for typeset!
s as well : of: make op! function ['word 'value] [
either any [
attempt [out: reflect get value word]
attempt [out: reflect value word]
attempt [
if all [
typeset? t: get word
block? value
][
out: parse value [collect any [keep t | skip]]
]
]
attempt [
type!: get to-word head change back tail to-string word #"!"
rule: compose/deep [collect any [keep (type!) | skip]]
out: parse value rule
]
attempt [out: parse get value rule]
][out][
cause-error 'user 'message ["Bad arguments!"]
]
]
; make op! [['word 'value /local out t type! rule]]
t: make typeset! [integer! float!]
; make typeset! [integer! float!]
t of [1 2.3 "foo" <ba> 3 4.4 <f>]
; [1 2.3 3 4.4]
>> scalars of [#"a" 1 3.0 a :g 5%]
== [#"a" 1 3.0 5%]
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]]
]
]
'words of system
;== [version build words platform catalog state modules codecs schemes ports locale options script standar...
'words of #(a 1 b 2)
;== [a b]
'spec of :collect
;== [{Collect in a new block all the values passed to KEEP function from the body block}
body [block!...
number! of [1 a 3.0 b]
;== [1 3.0]
reflect
is one thing, but making a mish-mash of Parse, reflection and what-not is another (which I personally do not support).