This is a continuation from the previous post.
When we communicate, which programming is, we try to be not overly verbose and redundant. Communication between people usually happens inside some context hierarchy. A fork when two programmers chat is a different thing than when two chefs do.
One of the goals of Rye is to enable succinct, well flowing code and use of short words for functions helps with that. That's why generic methods are an important part of the language. Many times the first argument providing the context works well. But sometimes this is redundant also.
Given that the contexts/scopes are first class Rye values, we can construct a context that holds all words of our Raylib game engine. Contexts can link to parent context, so Raylib words have a priority, but everything else works as normal.
Let's create this context:
And use it. Comparable Go code is on the left:
Because we can create custom "looping constructs" in Rye, I just replaced for loop and a condition check with a simpler world main-loop that does this.
We already had a function do-in (context), but with-context sounded clearer here so I renamed it. There are also other ways to run code with a given context, for examples via word fnc on a function level.
A little more involved example below makes the golden ball continuously travel from the left to the right of the window.
Btw. I started writing Rye at a glance on the readme page on github repo.
Komentarji
Objavite komentar