Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -1,4 +1,4 @@
int i = 19
int i 19
^|ifthenelse|^
if i > 18
writeLine("greater than 18")
@ -6,14 +6,14 @@ else
writeLine("less or equal to 18")
end
^|else if|^
if i == 18 do writeLine("equal to 18")
if i æ 18 do writeLine("equal to 18")
else if i < 18 do writeLine("less than 18")
else do writeLine("greater than 18")
end
^|when expression: just like iif in Visual Basic|^
writeLine(when(i > 18, "greater than 18", "less or equal to 18"))
^|hash-based conditionals|^
Map dispatch = int%fun[
18 => <|writeLine("equal to 18"),
19 => <|writeLine("yeah, it's 19")]
Map dispatch int%fun[
18 <|writeLine("equal to 18"),
19 <|writeLine("yeah, it's 19")]
if dispatch.has(i) do dispatch[i]() end

View file

@ -1,4 +1,4 @@
i = randint 10
i = random 10
if i mod 2 = 0
print i & " is divisible by 2"
elif i mod 3 = 0

View file

@ -0,0 +1,2 @@
g/True/s//It's true!/p
v/True/s/.*/It's false!/p

View file

@ -0,0 +1,9 @@
SELECT
IF(can_fly, 'Superman', 'Batman'),
-- replace NULL with string
IFNULL(can_fly, 'Not clear if this user can fly'),
-- alias for IFNULL
NVL(can_fly, 'Not clear if this user can fly'),
-- replace '' with NULL
NULLIF(can_fly, '')
FROM user;

View file

@ -0,0 +1,12 @@
SELECT
-- return the first non-NULL value
COALESCE(email, phone, telegram_id) AS contact,
-- replace the key (1) with corresponding value ('email')
CASE contact_type WHEN 1 THEN 'email' WHEN 2 THEN 'phone' ELSE NULL END AS contact_type,
-- the first parameter must be a 1-based integer,
-- ELT() returns the nth argument (eg, for n=1 it will return the email column)
ELT(n, email, phone, telegram_id) AS preferred_contact,
-- returns the index of the value that is equal to the 1st argument:
-- in this example, 2
FIELD('phone', 'email', 'phone', 'telegram_id') AS type;
FROM user;

View file

@ -0,0 +1,14 @@
BEGIN NOT ATOMIC
IF @b IS TRUE THEN
SELECT '@b is true';
ELSEIF b IS FALSE THEN
SELECT '@b is false';
ELSE
SELECT '@b is null';
END;
CASE @b
WHEN TRUE THEN SELECT '@b is true';
WHEN FALSE THEN SELECT '@b is false';
ELSE SELECT '@b is null';
END CASE;
END;

View file

@ -0,0 +1,10 @@
foo templates
when <|=0> do 'zero' !
when <|..0> do
'negative ' !
-$ -> # !
when <|?($ mod 2 matches <|=0>)> do 'even' !
otherwise 'odd' !
end foo
2 -> if <|3..5> -> $ + 10 !