https://gist.github.com/drakeirving/b0d0a8400c1cfff80385f95e5d6d9d3e
Oooh. That's some good stuff and gives me a lot of insight.
- I would not have thought of finding truthiness like that. Do max and abs work on all types, or are they just being short-circuited by the len==0?
- I assume that the length of a char or bool would be 0, so it must work on those - I assume it treats chars as numbers, true as 1, and false as 0?
- It seems like an array (or string) is never truthy by this definition? That seems contrary to the usual definition, where everything except certain values are truthy.
- I didn't realize Danmakufu allowed implicitly evaluating numbers as part of logical expressions. Is that what the !! around it is for?
- I had assumed you couldn't use length on things other than arrays, very happy to see I was wrong.
- Is the purpose of x[0..0] instead of x[0] to keep it as an array? ...And then ToString on x[0..0] gives you "" if it's a string? How does that work?
- Are there any known inputs that will result in returning TYPE_UNKNOWN, or is that just a failsafe?
- Arrays are typed
So I've noticed - the big thing I need this for (apart from general use) is figuring out the type of arrays so I can safely append a hash to them before notifying events, which will use the hash to pass back a value through common data.
How deeply are arrays typed? Does a multidimensional array always need to have the same depth in all member arrays? I've been operating under the assumption that they do, but I've been wrong before.
- Strings are character arrays, i.e. "abc" == ['a','b','c']
I knew this was the case in other languages, but didn't want to assume the two were equivalent in Danmakufu. Good to have confirmation that they are.
- Shower thought: Strings should have been called "charrays".
- If you type [] inside a script it defaults to a char array
- Empty arrays can be turned into another type of array
Does this mean
[] and
"" are functionally equivalent? If so, does it actually affect anything that they default to char arrays?
I notice you have a case for determining it to be an empty array (rather than an empty string), but typeof([]) still returns TYPE_ARRAY_CHAR?
While I'm at it, is
NULL literally just a constant for 0 or is there anything special about it?
- ? Infinity should be treated as valid numbers. NaNs also technically work without errors but have behaviour inconsistent with numbers.
Doesn't ?INF00 also have behavior inconsistent with numbers? I believe anything you do to it can only result in ?INF00, IND00, or QNAN0. Still, I wouldn't want to accidentally skip appending something to an array just because it was divided by zero and end up with weird confusing behavior, so I see the value of treating it as a number.
IND00 is a bit harder to end up with (0/0, sqrt(-n), or INF00*0 are the only ways I've found) and has even weirder behaviors (comparison is all sorts of fucked with it IIRC) so I also see why you wouldn't want to treat that or QNAN0 as numbers. Easy way to get
undefined behavior, amirite?
E: Random question, is there a way to do regex in DNF, or would I have to use a function to do it manually? Mainly asking because I'm sure this is another thing that would be fascinating to see your implementation of, if you have one lying around.
EE: Is there a way to cast
to char? Other than making an array containing the char for each value and taking that index from it?