empty array element require elision=true #1407
Replies: 7 comments
-
Posted at 2020-05-31 by @allObjects é,
Espruino JavaScript interpreter works anyway... with your original as well as with this editor satisfying code above. If you have more, longer ones or more sparse ones of those arrays, a different way to initialize may save you space if space is an issue. For a space optimal initialization range of the values can be considered in the filling algorithm. I'll add another post about that. I'm sure you are aware of the differences of
and
. TL;DR: - in regard of elision The IDE editor has a linter that by default obviously dislikes elision / trailing commas for empty values / comma following another comma without a value / token in between. Elision (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas) is from cleanness of a language not a good thing... and risk misunderstanding (but a desired thing when space and execution speed matter as w/ Espruino. JavaScript has some other creepy thing: line ends can give you the creeps,... and semicolons too. It's the same with spoken languages: if you are not very fluent and someone speaks with a lots of elisions - and local dialects often have that - you have a hard time to understand. The Editor tries to make coding in JS robust and safe, that's why it even flags missing semi colons, even though the language execution allows it. I do not know what happened to the editor in IDE... but recently this multi file edit came in and with that may be a new version of the syntax checker / linter or just a new configuration. I hope @gfwilliams can answer what to do in the environment. The editor just speaks of warning... but the code may still run. PS: from a compiler parser point of view, I always felt the continuation information - in this case the comma - to be misplaced when put at the end - and a coding / logic trap, because most languages do not allow in a list for the last element to have a continuation indicator but no continuation element. For that reason, you see a lot of my code doing the continuation character on the next line (I know that the parser then has to be a bit smarter than a simple line oriented parser is... but since practically all languages require from syntax / tokenizing / non-terminal syntax element / terminal syntax element - or simply said: ignore white spaces (blanks, tabs, new lines), having the continuation indicator together with the continuation element and the list delimiter on a separate line. This relieves you from having to consider wether an element is the last element in the list and also allows you to move lines around / rearranging order of lines as a whole without having to think about this special cases. The only special case is the first element... An example makes that obvious:
Any moving around of (continuation) lines or adding lines (with leading comma) is a pure editing thing, can be done as a whole line including line end and has no impact on syntax. Only when I have to deal with the very first element, then it needs some thinking. PS: Because I'm still a of hte Niklaus Wirth programming school, it was never a thing for me, even though JavaScript introduced it in ECMA Script 5 a while ago. I do not like omissions because they are potential traps... (even tough in Espruino I use for space reasons the opposite... so guilty as charge: I can avoid the NP: The behavior of the forum post editor has changed too (or may be it is the os of the mac or chrome as the browser: more recently, when typing a second (and/or third) blank in a row it is replaced with a fullstop. This makes me crazy when writing code. Try it yourself: Instead of typing a full stop at the end of a sentence, just hit the space twice after the last word. I can see that this is useful for text, but not for code. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-05-31 by @allObjects Just for the sake of fun, I did annotate your- pretty sparse - array of 256 elements (bear with me, it i a lot of nothing / undefineds / u's):
Initially I had the thoughts of the following pattern: in an initializing table, you identify the streaks, their lengths and values. For each streak you have basically these for value groups:
To make it more efficient for streaks of one, you put the value in negative and no need for the length of a streak. A simple algorithm initializes in So your initialization array ```ia`` would then look like this (only first few streaks)
The other approach which requires less spade in the initialization array but may be a bit more investment in the initializing algorithm is to have a bit list where values go and then just a the list of the values. Since 256 bits fill exactly 2 4-byte words or integers, you need only 8 bytes to describe where something goes and where nothing goes. Since this is so efficient, you may not even go to the integer encoding but use just a hex string. Remember, source area bytes taken away from variables - of course so does code. Using data directly from flash memory can save you space as well... So the bit list in hex - which you convert on the go nibble by nibble with LSBit first - looks like this;
For both, the initialization algorithms are simple: walking the streaks or walking the bit list and value list in parallel. Would be interesting - as a next step - to have the 'savings factor' figured out... The more arrays the more savings since the algorithm is required only once... where as the no space has to be defined for every single array. I don't know how you came up with the initial array. Generating the streaks or bit and value lists is for sure something for a generator / translator from the raw string / original source. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-01 by Mrbbp hello @allObjects, The array is the char width (of a slanted font), and the index (position in the array) is the ascii code of the letter. as i use accents, i use extended ascii table (255 members)
i rewrite the array é. Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-01 by @allObjects thank you for elaborating a bit more on the subject you are working on. To answer your question 'What is a streak?': A streak is some kind of a succession / repetition / burst / sequence... - because not of (American) English mother tongue myself, I hope I did not make a typo fool of myself with this. Any way, I should have used the term 'sequence' (of non-null values). Since characters are looked up by their ASCII code, the table has to look your way. Since the code works - Espruino can handle elision - and only the Web. IDE complains, just keep going your way. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-01 by @gfwilliams
I'm pretty sure that's the case. I think if you run it, it'll be fine - the editor just warns because often if you do |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-01 by Mrbbp @gfwilliams oh it works i just wanted to understand what the app ide wanted me :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-01 by Mrbbp thanks, now i understand better. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-05-31 by Mrbbp
with this a partially fill array, the web ide send me a message about elision.
what i'm suppose to do?
i do not understand the message!
i do not want to fill the array, if it's empty, it's "undefined", i test it and do something if it true or not...
Would you explain goo doesn't answer to me :/ (sorry)
do i have to change something, because it seems to work on the espruino!
thanks for your help
Beta Was this translation helpful? Give feedback.
All reactions