-
• #2
é,
this works for you (gets rid of the warning):const u = undefined; const lL = [u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,2,2,u,4,u,u,u,0,4,4,u,5,u,3,2,4,0,1,u,u,u,u,u,u,u,u,2,2,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,4,u,4,u,u,u,4,4,3,3,3,3,5,5,2,3,4,3,6,4,3,6,4,5,3,3,3,4,5,4,5,4,u,u,u,u,u,u,2,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,4,u,4,u,u,u,u,3,3,3,3,3,u,u,2,2,u,u,u,u,3,u,3,u,u,3,u,3,3,u,u,2]; for (const l of lL) { if (l == undefined) { console.log("vide"); } else { console.log(l); } }
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
for (const l of lL) {
and
for (const l in lL) {
.
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 @Gordon 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:
var arr = [ "all" // first , "objects" , "are" , "things" ];
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
var aVar
declaration in a function and save that space by adding it as a parameter in the parameter list. Even when the caller puts too many parameters there I can get away practically all the times.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.
-
• #3
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):
const u = undefined; const lL = [u // 0. -- nib 0 ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,2 // 32.+33. = 2x -- nib 4 ,2 // ,u ,4 // 35. = 1x ,u // -- nib 5 ,u ,u ,0 // 39.-41. = 3x ,4 // -- nib 6 ,4 // ,u ,5 // 43. = 1x ,u // -- nib 7 ,3 // 45.-49 = 5x ,2 // ,4 // ,0 // -- nib 8 ,1 // ,u ,u ,u ,u ,u ,u ,u ,u ,2 // 58.+59. = 2x ,2 // ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,4 // 91. = 1x ,u ,4 // 93. = 1x ,u ,u ,u ,4 // 97..122. = 26x ,4 // ,3 // ,3 // ,3 // ,3 // ,5 // ,5 // ,2 // ,3 // ,4 // ,3 // ,6 // ,4 // ,3 // ,6 // ,4 // ,5 // ,3 // ,3 // ,3 // ,4 // ,5 // ,4 // ,5 // ,4 // ,u ,u ,u ,u ,u ,u ,2 // 129. = 1x ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,u ,4 // 224. = 1x ,u ,4 // 226. = 1x ,u ,u ,u ,u ,3 // 231..235. = 5x ,3 // ,3 // ,3 // ,3 // ,u ,u ,2 // 239.+240. = 2x ,2 // ,u ,u ,u ,u ,3 // 244. = 1x ,u ,3 // 246. = 1x ,u ,u ,3 // 249. = 1x ,u ,3 // 251.+252. = 2x ,3 ,u ,u ,2 // 255. = 1x ];
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:
- Index of where the streak begins
- Length of the streak
3.,4.,5... Values of the streak.
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
onInit()
called function the working arraywa
from the initialization arrayia
and then you throw the initialization array away... (withdelete ia;
).So your initialization array `
ia
would then look like this (only first few streaks)var ia = [32,2,2,2 ,35,-4 ,39,3,0,4,4 ,45,5,3,2,4,0,1 ,... ];
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;
var bl = "0000B8BE3..." // nibbles 0..8 - bit list for first 36 array locations var vl = [2,2,4,0,4,4,5,3,2,4,0,1,...]; // values for the 12 array locations that have a value
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.
- Index of where the streak begins
-
• #4
hello @allObjects,
wow, it's really hard for my poor english to understand all you're writing (and goo translate is shameful)...
what is a "streak" in this particular context?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 use an other array, an object to be accurate, for kerning letters. (i rewrited 3 time my
algorithm, and now it's quicker)
because the font is slanted, his char width is wrong withg.stringWidth(char)
.const charWidth = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3,2,,4,,,,0,4,5,4,2,1,3,0,5,4,4,4,4,,,,,,,2,2,3,3,4,3,,4,4,4,4,4,4,4,4,3,4,4,4,5,4,4,4,4,4,4,3,4,4,5,4,4,4,,,,,,,4,4,3,3,3,3,5,5,2,4,4,3,6,4,3,6,4,5,3,3,3,4,5,4,5,4,,,,,,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,4,,4,,4,,,4,4,4,4,4,,,,,,,,,,,,,,,,,,,,,3,,4,,,,,3,3,3,3,3,,,3,3,,,,,3,,3,,,3,,3,3,,,2]; const aKerning = { 'a':["ad+1","al-1","af-1","ag+0","ai-1","am+0","an-1","ap-1","ar-1","au+1","as+0","av+1"] ,'b':["bi-1","bl-1","bo+0","br-1","bs-1"] ,'c':["ci-1","cl-1","cu+1"] ,'d':["de+1","di+0","dr+0","du+1","d'+1"] ,'e':["ea+1","ec+1","eg+1","ep-1","er+1","es+1","et+1","eu+2","ev+2","ez+1"] ,'é':["éâ+1","éc+1","ée+1","éj+1","éo+1","ép-1","ér+0","és+1","ét+1","év+2"] ,'è':["ès+1","èt+1"] ,'ê':["êt+1"] ,'Ê':["Êt-1"] ,'f':["fe+1","ff-1","fl+0","fo+1","fu+2"] ,'g':["gi-1","gn+0","gl-1","gu+1"] ,'h':["hi-1","hr-1"] ,'i':["iA+1","ib+1","ic+1","id+1","ie+1","ié+1","iè+1","ig+1","io+1","iq+2","ir+1","is+1","it+1","iv+2","ix+1","iz+1"] ,'j':["ju+1"] ,'k':[] ,'l':["lé+0","li-1","ll-1","lv+1","l'+1"] ,'m':["ma+0","mb+0","mi+0","mm-1","mp-1","mu+1"] ,'n':["na+1","nc+1","nd+2","ne+2","né+1","nj+1","nn+0","no+1","nt+1","nv+2","nu+2"] ,'o':["ob+1","oc+1","od+2","oe-1","oè+1","oo+1","om+1","op-1","os+1","ot+1","ou+2","ow+1"] ,'p':["pé+0","pi-1","ph-1","pl-1","po+0","pp-2","pr+0"] ,'q':["qu+0"] ,'r':["ré+0","rg-1","ri-1","rl-1","rm-1","rn+1","rr-2","rs+1","ru+1","rv+1"] ,'s':["sa+1","sc+1","se+1","so+1","sp-1","sq+1","st+1","su+1"] ,'t':["ta+0","té+0","th-1","ti-1","tr-1"] ,'u':["ud+1","ue+1","ui+0","ul+0","um-1","un-1","up-1","uq+1","ut+1","uv+1"] ,'v':["va-1","ve-1","vi-1","vo-1","vr-1"] ,'w':["wh+0","wr-1"] ,'x':[] ,'y':["yn-1","ys-1"] ,'z':["z-+1"] };
i rewrite the array
aKerning
with the comma at the beginning of the line (easier to read ;). Thanksé.
1 Attachment
-
• #5
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.
-
• #8
thanks, now i understand better.
And yes, i 'm agree that a patterned sequence of value could be shortened but it was not my goal yet ;)
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