Henrik Bengtsson on Nostr: Thought experiment: What would be possible if we could declare an #RStats object ...
Thought experiment: What would be possible if we could declare an #RStats object read-only, eg
x <- 0:9
readonly(x) <- TRUE
x[2] <- 4L
# Error: Object 'x' must not be modified
or lock its type, eg
x <- 0:9
coercable(x) <- FALSE
x[2] <- 4
# Error: Object 'x' must not be coerced: integer -> numeric
Things I can imagine:
* protect against thinkos and bugs
* early error detection
* further {compiler} code compilation
* cleaner code, e.g. less manual assertions
* enhanced code completion
* …?
Published at
2024-04-03 03:37:05Event JSON
{
"id": "064c6d5738654670da9659d5688226d5c2e57b1e51ea448f39db80c28cbf3a80",
"pubkey": "042aae24355e3a9a908d3ea04fa667c0823466d0fd0fe5614d95718cb7724c58",
"created_at": 1712115425,
"kind": 1,
"tags": [
[
"t",
"rstats"
],
[
"proxy",
"https://mastodon.social/users/henrikbengtsson/statuses/112205196514049052",
"activitypub"
]
],
"content": "Thought experiment: What would be possible if we could declare an #RStats object read-only, eg\n\nx \u003c- 0:9\nreadonly(x) \u003c- TRUE\nx[2] \u003c- 4L\n# Error: Object 'x' must not be modified\n\nor lock its type, eg \n\nx \u003c- 0:9\ncoercable(x) \u003c- FALSE\nx[2] \u003c- 4\n# Error: Object 'x' must not be coerced: integer -\u003e numeric\n\nThings I can imagine:\n\n* protect against thinkos and bugs\n* early error detection\n* further {compiler} code compilation\n* cleaner code, e.g. less manual assertions\n* enhanced code completion\n* …?",
"sig": "8b5bcacea79d79d601b6af78cfcebfef1ba88b977c26955e42553ee8ef8a28555f29ac8048eee0fedc3cb3b5734da7a8cce27b410b727bc6ed8e94c8802fc104"
}