s |
focus search bar ( enter to select, ▲ / ▼ to change selection) |
g e |
go to examples |
g m |
go to modules |
g o |
go to overview |
g r |
go to reference |
h |
toggle this help ( esc also exits) |
$$
Signals the compiler to bake a function when the value of the operand parameter is known at compile time. 1
// from: https://youtu.be/7Fsy2WaxLOY?t=3110
Spacing_Mode :: enum {
NONE,
INDENT,
EXDENT
}
using Spacing_Mode.members;
print_names_and_values :: (names: [] string, values: [] int, $$ mode: Spacing_Mode.strict, use_dots: bool) {
if mode == EXDENT printf(" ");
printf("print_names_and_values says:\n");
for 0..names.count-1 {
if mode == INDENT printf(" ");
printf("%8s:", names[it]);
if use_dots printf("......");
else printf(" ")
printf("%d\n", values[it]);
}
}
N :: 5;
names : [N] string;
values : [N] int;
names[0] = "Cow";
names[1] = "Horse";
names[2] = "Pig";
names[3] = "Mule";
names[4] = "Llama";
values[0] = 1;
values[1] = 4;
values[2] = 6;
values[3] = 4;
values[4] = 1;
print_names_and_values(names, values, NONE, false);
print_names_and_values(names, values, INDENT, true);
[in procedure print_names_and_values
], you may have noticed this funny $$
up here, before the variable mode
, and what that means is anytime, anywhere in the program where you call print_names_and_values
if the value that you’re passing for Spacing_Mode.strict
is known at compile time [..], then auto-bake this function so that only these are really the parameters and this one is hard-coded so that the code gets generated with mode
as a constant, so that you don’t have to pay for these if
statements.
“Polymorphic Procedures, part 2” YouTube, uploaded by Jonathan Blow, Apr 1, 2015, https://youtu.be/7Fsy2WaxLOY?t=3150 ⮌
jailang
2019 pixeldroid
https://github.com/pixeldroid/jailang |
programming pages theme v0.5.21 (https://github.com/pixeldroid/programming-pages) |
s |
focus search bar ( enter to select, ▲ / ▼ to change selection) |
g e |
go to examples |
g m |
go to modules |
g o |
go to overview |
g r |
go to reference |
h |
toggle this help ( esc also exits) |