User:Userring/sandbox

This is my user sandbox. Again I am writing this as part of a task in GCI 2019

Task 1


imgs

Task 2
Q1. What keyword marks the start of a function definition? A1. function

Q2. Which letter is conventionally used in Scribunto modules to hold the table of functions? A2. p

Q3. What keyword marks the end of a function definition? A3. end

Task 3
Testing the function with different testcases, such as invalid and nil input:

Both of these use 0 degrees Celsius as in the function, if there is no input/ the parameter is nil, 0 degrees will be used instead for the conversion. For invalid input, the built-in function tonumber returns nil if the input parameter is not an integer or a string capable of being converted to an integer thus 0 is used.

Testing the function with different inputs above and below 9:

9 itself returns "It is cold" as we are only checking for integers that are "strictly" greater than 9 and not including 9.

Testing if the function works with floats and integers that have been converted to strings(e.g. "20"):

'5' should not return 0 degrees Celsius as it is a "string convertible to a number" and thus should return 5 when inputted into the built-in function tonumber however this is not the case and I am unable to find out why this is the case. When I tried tonumber("5") in the console of the Module sandbox, the integer 5 was outputted however, for testing, when I previewed this sandbox where I returned tonumber(frame.args.celsius), nothing was returned when the paramater was "5".

Edit: Parameters that are passed into modules are passed in as strings. As a result, passing in "5" will convert "5" into a string making it ""5"". When tonumber tries to convert this into a number, it is converting ""5"" instead of "5", the former not being a string convertible into a number, the latter being a string convertible into a number. Thank you to for explaining it in greater detail below.


 * The problem is that there is a difference in the Scribunto implementation between the processing of parameters passed through #invoke (which are all converted to strings) and whatever is passed through the debug console. The debug console runs code directly, so that  will treat the   as simply the byte code 0x35, the ASCII code for the digit 5, as a string. That will be converted by the   function as the number 5. However, when you pass   as the value of a parameter, it literally stores the three byte sequence 0x27 0x35 0x27 as a string. That returns nil from the   function, as you can test by typing   in the debug console. Hope that makes sense. --RexxS (talk) 19:57, 7 December 2019 (UTC)

Task 4
Testing the function for various testcases with different types of inputs, e.g. nil, no parameter inputted, the integer in text form and negative numbers.

Both of the first two use the 2 Times Tables as if there is no input/ the parameter is nil, 2 is used instead for the times tables as we are using the "or" logical operator. For the third testcase, "four" cannot be converted into a number as it is not a "string convertible into a number" and thus when inputted into the built-in function tonumber, nil is returned. This is the case for all invalid input. For the last testcase, the Times table of -4 is returned, as although -4 is a negative number, it is still a number/ integer and thus tonumber returns -4 and not nil and the Times table of -4 is returned from the function.

For changing the times table to display x number of times, the maximum value of the for loop has to be changed to x as it is inclusive of that value.

Tables
The names of the friends are displayed twice, although the task doesn't say so, however, I just decided to display the two different ways of iterating over an array even though they return the same output. I have given the full explanation below. I may have done something wrong and tried something absolutely foolish so please correct me.

As said in the task briefing, list indexing starts at 1 rather than at 0 like in programming languages such as Python and others...(let me look some up) such as Java, C#, C and C++. Although list indexing starting at 1 seems more logical, looking at some articles online, list indexing starts at 0 due to something to do with memory allocation and pointers in C. As you can probably tell from my writing, this isn't something that I completely understand but will abide by this as it is like a "rule" that is set and just go with the flow.

The "#" in front of a array returns the length of the array and thus can be st as the upper limit of the for loop. This enables the for loop to iterate over the array. There is also another way I found to iterate over the array. The only reason I searched this up is due to their being a simple way in Python to do so and that is by doing "for something in array", something being anything such as a character or string. The other way to do it in Lua is by using the ipairs function which "allows iteration over index-value pairs". I found that you can use ipairs to iterate over arrays in a stackoverflow post and further researched it using lua manuals. I appended to the function the ipairs way of iterating over the array although the task doesn't say to do so and both the for loops give the same output.

Task 5
The string.sub function gets the substring of a string with the parameters inputted as follows: string.sub(string_name, initial_index, final_index). In string_name, the name of the string is given. In initial_index, the index of the character from which the substring starts from is inputted. This is inclusive and indexing starts at 1, therefore the first character would have the index of 1. The final_index is the index of the character where the substring ends. This is inclusive, thus the character at this final_index will be included in the substring. For example, if a s = string then string.sub(s, 1, 2) will return st.

The string.upper function capitalises all the ASCII lowercase letters only and leaves the other characters the same, thus if the integer 0 was passed into the function, 0 will be returned/ outputted from it as 0 is not an ASCII lowercase letter. The same goes for any letters that are already capitalised. For examples, string.upper(5tbAd) will return 5TBAD, the "5" and the "A" remaining unchanged due them not being ASCII lower case letters.

Q1. What does %w+ match in a Lua pattern? A1. %w+ matches 1 or more repetitions of all ASCII alphanumeric characters. These repetitions items will always match the longest possible sequence.

Q2. What does %d+ match in a Lua pattern? A2. %d+ matches 1 or more repetitions of all digits. These repetitions items will always match the longest possible sequence.

local m, d, y = string.match(dmy, "(%w+) (%d+), (%d+)")

In the American formatting of the date, the month and the day are switched around thus, first we have to change the month and day around of how we recognise them by switching around the first (%d+) and (%w+). As well as that, we have to change what we assign the recognised items to as we cannot assign the date to the month and vice versa.

If you were to access the previous versions of this sandbox and my Module sandbox, you will be able to see a working version of the American style of dates.

Task 6
The fallback langauges of Polish(pl)

The fallback languages of Eastern Min(cdo)

The fallback languages of Gan-Chinese(gan)

The fallback languages of Slovak(sk)