Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,30 @@
with Ada.Strings.Unbounded, Ada.Text_IO;
procedure Variadic is
subtype U_String is Ada.Strings.Unbounded.Unbounded_String;
use type U_String;
function "+"(S: String) return U_String
renames Ada.Strings.Unbounded.To_Unbounded_String;
function "-"(U: U_String) return String
renames Ada.Strings.Unbounded.To_String;
type Variadic_Array is array(Positive range <>) of U_String;
procedure Print_Line(Params: Variadic_Array) is
begin
for I in Params'Range loop
Ada.Text_IO.Put(-Params(I));
if I < Params'Last then
Ada.Text_IO.Put(" ");
end if;
end loop;
Ada.Text_IO.New_Line;
end Print_Line;
begin
Print_Line((+"Mary", +"had", +"a", +"little", +"lamb.")); -- print five strings
Print_Line((1 => +"Rosetta Code is cooool!")); -- print one string
end;

View file

@ -0,0 +1,58 @@
program-id. dsp-str is external.
data division.
linkage section.
1 cnt comp-5 pic 9(4).
1 str pic x.
procedure division using by value cnt
by reference str delimited repeated 1 to 5.
end program dsp-str.
program-id. variadic.
procedure division.
call "dsp-str" using 4 "The" "quick" "brown" "fox"
stop run
.
end program variadic.
program-id. dsp-str.
data division.
working-storage section.
1 i comp-5 pic 9(4).
1 len comp-5 pic 9(4).
1 wk-string pic x(20).
linkage section.
1 cnt comp-5 pic 9(4).
1 str1 pic x(20).
1 str2 pic x(20).
1 str3 pic x(20).
1 str4 pic x(20).
1 str5 pic x(20).
procedure division using cnt str1 str2 str3 str4 str5.
if cnt < 1 or > 5
display "Invalid number of parameters"
stop run
end-if
perform varying i from 1 by 1
until i > cnt
evaluate i
when 1
unstring str1 delimited low-value
into wk-string count in len
when 2
unstring str2 delimited low-value
into wk-string count in len
when 3
unstring str3 delimited low-value
into wk-string count in len
when 4
unstring str4 delimited low-value
into wk-string count in len
when 5
unstring str5 delimited low-value
into wk-string count in len
end-evaluate
display wk-string (1:len)
end-perform
exit program
.
end program dsp-str.

View file

@ -1,15 +1,15 @@
^|EMal supports variadic functions in more than one way|^
fun print = void by text mode, List args do
writeLine("== " + mode + " ==")
fun print ← void by text mode, List args
writeLine("[" + mode + "]")
for each var arg in args do writeLine(arg) end
end
fun printArgumentsList = void by List args
fun printArgumentsList void by List args
print("accepting a list", args)
end
fun printArgumentsUnchecked = void by some var args
fun printArgumentsUnchecked void by some var args
print("unchecked variadic", args)
end
fun printArgumentsChecked = void by text subject, logic isTrue, int howMany, some text values
fun printArgumentsChecked void by text subject, logic isTrue, int howMany, some text values
print("checked variadic", var[subject, isTrue, howMany, +values]) # unary plus on lists does list expansion
end
printArgumentsList(var["These are the ", true, 7, "seas", "of", "Rhye"])

View file

@ -0,0 +1,6 @@
(defun my-print-args (&rest arg-list)
(message "there are %d argument(s)" (length arg-list))
(dolist (arg arg-list)
(message "arg is %S" arg)))
(my-print-args 1 2 3)

View file

@ -0,0 +1,2 @@
(let ((arg-list '("some thing %d %d %d" 1 2 3)))
(apply 'message arg-list))

View file

@ -0,0 +1,8 @@
procedure print_args(sequence args)
for i = 1 to length(args) do
puts(1,args[i])
puts(1,' ')
end for
end procedure
print_args({"Mary", "had", "a", "little", "lamb"})

View file

@ -0,0 +1,5 @@
function print_all {
foreach ($x in $args) {
Write-Host $x
}
}

View file

@ -0,0 +1 @@
print_all 1 2 'foo'

View file

@ -0,0 +1,2 @@
$array = 1,2,'foo'
Invoke-Expression "& print_all $array"

View file

@ -0,0 +1 @@
print_all @array

View file

@ -0,0 +1,11 @@
REBOL [
Title: "Variadic Arguments"
]
print-all: func [
args [block!] {the arguments to print}
] [
foreach arg args [print arg]
]
print-all [rebol works this way]

View file

@ -0,0 +1,4 @@
Fixpoint Arity (A B: Set) (n: nat): Set := match n with
|O => B
|S n' => A -> (Arity A B n')
end.

View file

@ -0,0 +1 @@
Definition nat_twobools (n: nat) := Arity nat (Arity bool nat (2*n)) n.

View file

@ -0,0 +1,5 @@
Require Import List.
Fixpoint build_list_aux {A: Set} (acc: list A) (n : nat): Arity A (list A) n := match n with
|O => acc
|S n' => fun (val: A) => build_list_aux (acc ++ (val :: nil)) n'
end.

View file

@ -0,0 +1 @@
Definition build_list {A: Set} := build_list_aux (@nil A).

View file

@ -0,0 +1 @@
Check build_list 5 1 2 5 90 42.

View file

@ -0,0 +1,11 @@
Lemma transparent_plus_zero: forall n, n + O = n.
intros n; induction n.
- reflexivity.
- simpl; rewrite IHn; trivial.
Defined.
Lemma transparent_plus_S: forall n m, n + S m = S n + m .
intros n; induction n; intros m.
- reflexivity.
- simpl; f_equal; rewrite IHn; reflexivity.
Defined.

View file

@ -0,0 +1,7 @@
Require Import Vector.
Definition build_vector_aux {A: Set} (n: nat): forall (size_acc : nat) (acc: t A size_acc), Arity A (t A (size_acc + n)) n.
induction n; intros size_acc acc.
- rewrite transparent_plus_zero; apply acc. (*Just one argument, return the accumulator*)
- intros val. rewrite transparent_plus_S. apply IHn. (*Here we use the induction hypothesis. We just have to build the new accumulator*)
apply shiftin; [apply val | apply acc]. (*Shiftin adds a term at the end of a vector*)

View file

@ -0,0 +1 @@
Definition build_vector {A: Set} (n: nat) := build_vector_aux n O (@nil A).

View file

@ -0,0 +1,2 @@
Require Import String.
Eval compute in build_vector 4 "Hello" "how" "are" "you".

View file

@ -0,0 +1,15 @@
proc print_all {args} {
puts stdout [join $args \t]
}
print_all 4 3 5 6 4 3
4 3 5 6 4 3
print_all 4 3 5
4 3 5
print_all Rosetta Code Is Awesome!
Rosetta Code Is Awesome!
print_all "Rosetta Code Is Awesome!" OK
Rosetta Code Is Awesome! OK

View file

@ -1,5 +1,10 @@
fn print_all(things ...string) {
for x in things {
println(x)
for val in things {
print(val)
}
}
fn main() {
print_all("Mary ", "had ", "a ")
print_all("little ", "lamb")
}