Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #227
This PR adds a
link
type to Dyon. It storesbool
/f64
/str
with only 3.2% overhead in memory compared to same-type-lists (when compactly filled), which is only 0.1% above theoretical minimum (2 bit) for a dynamical typed list like this. The link type is 1.5x faster at joining single items than arrays, and uses much less memory than arrays (3.096x).How to use a
link
objectA
link {}
bracket simply links together types ofbool
/f64
/str
in alink
object. White-space is optional, since the syntax can tell the difference between a string and a variable.You can compute stuff inside the bracket:
You can link single items with
+=
:Link together links with
+=
(puts it at the end) or-=
(puts it at the front):You can't use
+
because it wastes memory and is too easy to do. For more information, see #227. Instead, put it inside the link bracket:Motivation
The Dyon language has been very focused on vectors and mathematics up to now, but I would like a language that is also good at processing data, and good at generating and parse text, such as its own source. In Piston-Meta meta parsing there are only
bool
/f64
/str
, so an efficient structure to store these is perfect.The original idea evolved around an improvement of
all
/any
loops, but I decided to not go in direction with links because these are very small amount of data, and links seems perfect for doing large amounts of data. I want it to be really good at one thing: Link together data.There are lots of applications where you link together data:
However, the problem with generating text is that the process removes the information that makes the data useful, so you have to parse it again. By preserving this information one can reuse the data while keeping it close to the form of the final output.
Dyon uses the
go
keyword to turn a function call into a new thread, and links are very nice here since they can be passed between threads and efficiently linked in any order. When joining[thr[link]]
, you have to usepop(mut)
it to create a unique reference, or else Dyon will show an error. This reverses the order of the results. The-=
operator puts the links together in the right order.