Replies: 1 comment 1 reply
-
An idiom that is used internally for "refs" as you describe them is a 1 element array. This is how global variables are implemented, and while technically there is a little overhead, Janet isn't that kind of language. Basically, exploit that some types in Janet are passed by value, and others by reference. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider the following C snippet:
The procedure
mutate_field
takes a reference to a particular struct field to mutate. It cannot (within C best practices) touch the rest of the struct. This is basic encapsulation.How would we do the same in Janet? The closest thing we have to references are mutable structure bindings, and they can only touch the whole table at once:
A vague Janesque solution I can think of is
(ref {tab :field})
(name open to bikeshedding), which acts like standard field access/index except the original field reflects mutations in the yielded value:Though of course this quickly runs into edge cases. I'm curious to hear what others think.
Beta Was this translation helpful? Give feedback.
All reactions