This is a second post in a series. Click here to read the first one.
Modifier functions
So, when we have to, how do we change values of words outside our current context? The answer is "Explicitly".
Rye has a limited number of functions that change values of words in-place. They all end with exclamation mark. These functions currently are:
change! - changes a value and returns true if value was changed
inc! - increments a value in-place (like i++)
append! - appends a value or a block of values to a series in-place
purge! - higher order-like function that removes items from an series in-place
Ordinary functions in Rye don't change their arguments in-place. Rebol's and Python's functions or methods are more mixed bags about this. Append in Rebol both adds a new value to the existing series and returns it. Python's list.append() returns None and modifies the existing list.
Rye prefers expressions (not statements). Expression is something that returns a result rather than changes the state. Unless we literally want to modify a value/state or if the reason is optimization, we in Rye write expression based code.
You can always call ...
We can't change values in contexts from outside, but we can call into them. That's currently a desired limitation.
Smells like objects
Rye is not an object oriented language. It tries to lean towards functional concepts, if we need to be taking sides. Contexts could be used like objects, to encapsulate functionality and state, but that is not the usual or preferred code/state organization method.
I usually separate code and data. There are better types of Rye values for data like lists, dicts and dataframes (tables). And there is a concept of generic methods and kinds, which more resembles CLOS (Common List Object System) if you need dispatch. We won't go there now.
If the bull went, let ...
There is a saying in Slovenia "Če je šel bik, pa naj gre še štrik" - try to translate that :).
Just to show some more general context behavior, we could achieve something like inheritance in two ways (that are not there for inheritance's sake).
There will be no talk about fake object systems in the next posta about contexts.
Follow Rye's development on Github.
Komentarji
Objavite komentar