r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
501 stars 137 forks source link

minimal typecheck in node functions #388

Closed vspinu closed 6 years ago

vspinu commented 6 years ago

It would make sense to have a minimal stopifnot(is_node(x)) in each of the node_* functions. I am crashing R each time I pass wrong type by accident.

lionel- commented 6 years ago

These functions have been marked internal. Their only purpose currently is to prototype C code.

lionel- commented 6 years ago

We'll be thinking about a pairlist package, I've been doing lots of pairlist work in https://github.com/lionel-/redpen and https://github.com/lionel-/flowery. Nothing planned for now though.

vspinu commented 6 years ago

Their only purpose currently is to prototype C code.

I see that you use them in the main code. So it's not for prototyping only. I do use them to manipulate and construct pairlists and calls because there are no better tools out there except for going C level.

lionel- commented 6 years ago

I see that you use them in the main code. So it's not for prototyping only.

It's in the main code but in places that are meant to move to the C side. So it's C code prototyped in R.

You're welcome to create a more user-friendly package for working with pairlists but at this point we're not going to include this kind of functions in rlang. There seems to be little point investing time teaching users why and how to work with linked lists.

lionel- commented 6 years ago

Also note that the node pokers have reference semantics but only because of lazy copying. Lazy copying semantics are not guaranteed by the R language so the fact that it works is a bit of an happenstance (though there is no reason to think these lazy copying semantics are going to change).

vspinu commented 6 years ago

I just discovered call_modify which works just fine on pairlists (intended?). I will probably be moving all my stuff on top of it and avoid node_* altogether.

Though splice doesn't work within but unquoting does:

> call_modify(pairlist(a = 2), !!!(ll(a = 3, b = 3)))
$a
[1] 3

$b
[1] 3

> call_modify(pairlist(a = 2), splice(ll(a = 3, b = 3)))
$a
[1] 2

[[2]]
[[2]]$a
[1] 3

[[2]]$b
[1] 3