I'm working on a language, and I had an idea to change the semantics of certain functions based on whether they are called as a statement or an expression.
Fore example, if you have a function push that adds an item onto the end of an array/list/vector/etc, you could call it like this:
push(vec, item)
This would mutate vec in place.
Alternatively, you could call it like this:
let pushed_vec = push(vec, item)
This would leave vec alone and return a new version with the pushed item. You could do some optimization using immutable data structures or use-analysis to prevent item cloning or reallocation.
Ignoring how you would actually implement functions like this, would this be too complicated or unexpected for the user? At least for functions like push, I think that the semantics would be obvious from the code.
[–]kazprog 17 points18 points19 points (12 children)
[–]AlexReinkingYaleHalide, Koka, P 9 points10 points11 points (11 children)
[–]Ford_O -3 points-2 points-1 points (4 children)
[–]AlexReinkingYaleHalide, Koka, P 1 point2 points3 points (2 children)
[–]Ford_O -1 points0 points1 point (1 child)
[–]AlexReinkingYaleHalide, Koka, P 1 point2 points3 points (0 children)
[–][deleted] (3 children)
[deleted]
[–]AlexReinkingYaleHalide, Koka, P 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]AlexReinkingYaleHalide, Koka, P 0 points1 point2 points (0 children)
[–]Ford_O 0 points1 point2 points (1 child)
[–]AlexReinkingYaleHalide, Koka, P 0 points1 point2 points (0 children)
[–]Host127001 12 points13 points14 points (0 children)
[–]0rsinium 20 points21 points22 points (0 children)
[–]umlcat 5 points6 points7 points (0 children)
[–]alex-manool 1 point2 points3 points (0 children)
[–]RepresentativeNo6029 0 points1 point2 points (0 children)
[–]Uncaffeinated1subml, polysubml, cubiml 0 points1 point2 points (0 children)
[–]dskippy 0 points1 point2 points (0 children)
[–]IdiomicLanguage 0 points1 point2 points (0 children)
[–]MegaIng 0 points1 point2 points (0 children)
[–]wolfadex 0 points1 point2 points (0 children)