Ivan Reese
Ella Hoeppner
04/13/2024, 9:42 PMIvan Reese
oPOKtdJ4UbTdPaZig6jg
04/14/2024, 12:34 PMJarno Montonen
04/14/2024, 1:00 PMStefan
04/14/2024, 1:25 PMstring
type of that language translates to. But in C the trouble with const is that you either point to a constant value, and the pointer can still change, or you declare a constant pointer to a variable, and you canāt change the pointer, but you can change the value. Both of these need to be held in a read/write segment and I assume that is probably why your example copies the string contents o the heap?
In C you can use double const to explicitly have a constant pointer to a constant value, but I have no idea how that plays out when you compile it and no means to try it right now. I wouldnāt be too surprised if that also does something unexpected, given that C compilers have a lot of wiggle room in terms of āimplementation detailsā and āundefined behaviorā.
Swift has an explicit `StaticString` type that is used for literals and enables all kinds of compiler optimizations and compile-time shenanigans, like macros that are type-checked proper Swift code run at compile-time.ExpressibleByā¦Literal
protocol, which I guess would enable you to implement your own types with their own custom binary representations that can be specified as literals in the code and read and converted at compile time while treated as constants. How useful that really is though, Iām not sure.oPOKtdJ4UbTdPaZig6jg
04/14/2024, 2:29 PMJarno Montonen
04/14/2024, 2:36 PMKartik Agaram
Squirrel
04/14/2024, 5:59 PMWe would need to execute the parsing during compilation, but as far as I know no programming language allows allocation during compile time execution.Did you look at Zig?
ā¢ Call any function at compile-time.https://ziglang.org
In conclusion, declarative programming is nothing other than defining constants in a text form.Same goes for non-declarative languages. Think of Lisp.
curious_reader
04/14/2024, 6:49 PMoPOKtdJ4UbTdPaZig6jg
04/15/2024, 6:04 AMSquirrel
04/15/2024, 6:13 AMData structures like a graph that contains pointers to itself will need some extra work though.Looking at Rust, const data can contain references to const data as long as they are not circular. I don't really care though. I never put references in my const data, but instead put indexes that are relative to the base pointer of the const data. A reference is 8 bytes, so I don't want to have that in const data. An index is 1, 2 or 4 bytes depending on the size of the data. Sometimes I've even packed a 12-bit index and a 4-bit length in two bytes.
oPOKtdJ4UbTdPaZig6jg
04/15/2024, 6:31 AMSquirrel
04/15/2024, 6:45 AMoPOKtdJ4UbTdPaZig6jg
04/15/2024, 7:23 AMSquirrel
04/15/2024, 7:25 AMoPOKtdJ4UbTdPaZig6jg
04/15/2024, 7:40 AMSquirrel
04/15/2024, 7:42 AMpub static
instead of const
.
https://rust.godbolt.org/z/o9qc8d5Y4oPOKtdJ4UbTdPaZig6jg
04/16/2024, 4:23 AMSquirrel
04/16/2024, 7:16 AM