Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
It won't be too unidiomatic, I think, as many projects also use table-emulated enums in Lua.
Also, since the original description has changed, I copied the new description and made a change to it. But the diff of the descriptions are a mess now, and I don't know how to resolve it.
lol
approved
the other languages use an
enum
(except JavaScript where I tried to emulate one with an unmodifiable object whose keys are equal to their values). I tried to cobble together something equivalent for Lua, which does not have native enumerated types:Preloaded:
user solution:
tests:
What do you think ? is it too awkward / unidiomatic ?
i thought that scientific notation is easier to understand and more informative for beginners (for example it gives a better idea of how small subnormal numbers are), and I for one cannot easily read the hexadecimal notation. but if you think it's better it's not that big of a deal
I just think it's better to use hexadecimal notation here. Do you want me to switch to decimal scientific notation?
already handled here
thank you for this incredibly thorough explaination
done
thanks for making the changes, is there a particular reason why you use the hexadecimal notation for the floating point literals ?
Lua translation
Codewars works by receiving code as a piece of text from your web browser; saving it to a file ;executing it on their server with the appropriate compiler/interpreter; and returning the output to your browser. It follows that you can get information on the system that runs your code by calling the appropriate commands.
It's easy to establish that the server runs on Linux because of the low-level nature of C (for example the
__linux__
macro is defined); web servers also typically run on Ubuntu, and the x86_64 architecture has become almost ubiquitous for desktop computers. But you can make sure of that by running something like this on Codewars (i wrote it in C because it is the only language you trained, but you could do the equivalent in almost all the other languages on Codewars):Use this function on Codewars (just call it in the function you're supposed to write for the kata) and you will see:
So we know the endianness, OS, and architecture.
C is a compiled language and C compilers generate lower-level assembly code for a specific architecture. We've established that Codewars runs on Linux x86_64, so we only need to search which calling convention is used: the System V ABI. A calling convention is a way to precisely describe how functions are to be called in assembly and how they return. It specifies which arguments are to be put in which registers by the caller, what the callee has to restore before returning control, etc. Without a calling convention, the different parts of a program could not talk to each other and it would be impossible to write reliable code.
IEEE 754 is a techincal standard/specification for floating-point numbers. It's so widely adopted that it's become almost synonymous with them. Almost all programming languages use it for their
float
and/ordouble
datatypes.we've established that Codewars runs on a Little-Endian machine, so the bytes that represent the float value are going to be hardcoded in little endian order in the executable files (on disk) as well, as they will be directly loaded into memory (RAM) in the same order.
You should experiment with compiling and building C programs that are split between several files to get a better understanding of the process. The peculiarity of the Codewars setup is that it uses no header (
.h
) files, unlike most large C programs. The command basically goes likecc user_code.c tests.c
. Due to the absence of header files there is no mechanism to ensure that types are compatible between the two files. Alltests.c
knows (from a declaration) is that there is a functionint multiply(int, int)
that it can call, but nothing prevents you from writing e.g.double multiply(int a, float b, short c)
instead inuser_code.c
(which is the file that you edit when you train on a kata), and it will still compile and run (but will behave strangely); you can see it for yourself.I have known (not in great detail) about these things for some time now and it would be hard for me to give advice to a beginner on the best way to learn in 2025, especially within the current AI boom. Many Wikipedia articles give in depth descriptions of subjects such as calling conventions; cppreference.com is a good reference on C/C++ specifically, godbolt.org is good to see what your code compiles to in different languages/environments/compilers, I often use tsnippet.trust-in-soft.com to find bugs in my C programs. But none of these tools are aimed at beginners.
Could you please let me all the concepts that you have gone through ?
How have you managed to link all the terminologies together like:
linker cares about is that there is something called multiply associated with a callable piece of code
is an IEEE754 double number
(little-endian, hexadecimal notation)
what made you think it was little endian was it the assembly code ?System V AMD64 ABI that Linux uses
how are you associatting these termss with the code ?can you name the resource materials, concepts that I would need to learn in order to have knowledge like this.
Hello, I've updated the translation. Please review.
Hello, thanks for the translation. I am not experienced in Lua and have a few remarks:
why do you need to compute
nan
in preloaded ? can't you do have it in the tests, like?
I feel like the wording is ambiguous and can mislead beginners. How about something like "until Lua 5.3, all
number
s were IEEE 754 DP. Since 5.3,number
s variables can also hold 2s complement integers". What do you think ?Loading more items...