Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,39 @@
' version 15-09-2015
' compile with: fbc -s console
Sub printAll_string Cdecl (count As Integer, ... )
Dim arg As Any Ptr
Dim i As Integer
arg = va_first()
For i = 1 To count
Print *Va_Arg(arg, ZString Ptr)
arg = va_next(arg, ZString Ptr)
Next i
End Sub
' ------=< MAIN >=------
' direct
printAll_string (5, "Foxtrot", "Romeo", "Echo", "Echo", "BASIC")
' strings
Print : Print
Dim As String a = "one", b = "two", c = "three"
printAll_string (3, a, b, c)
' count is smaller then the number of arguments, no problem
Print : Print
printAll_string (1, a, b, c)
' count is greater then the number of arguments
' after the last valid argument garbage is displayed
' should be avoided, could lead to disaster
Print : Print
printAll_string (4, a, b, c)
Print
' empty keyboard buffer
While InKey <> "" : Var _key_ = InKey : Wend
Print : Print "hit any key to end program"
Sleep
End

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

@ -16,7 +16,7 @@ void showSum2(int[4] items...) {
}
void main() {
printAll(4, 5.6, "Rosetta", "Code", "is", "awseome");
printAll(4, 5.6, "Rosetta", "Code", "is", "awesome");
writeln;
showSum1(1, 3, 50);
showSum2(1, 3, 50, 10);

View file

@ -0,0 +1,8 @@
defmodule RC do
def print_each( arguments ) do
Enum.each(arguments, fn x -> IO.inspect x end)
end
end
RC.print_each([1,2,3])
RC.print_each(["Mary", "had", "a", "little", "lamb"])

View file

@ -0,0 +1,29 @@
let
fix = // Variant of the applicative order Y combinator
f => (f => f(f))(g => f((...a) => g(g)(...a))),
forAll =
f =>
fix(
z => (a,...b) => (
(a === void 0)
||(f(a), z(...b)))),
printAll = forAll(print);
printAll(0,1,2,3,4,5);
printAll(6,7,8);
(f => a => f(...a))(printAll)([9,10,11,12,13,14]);
// 0
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10
// 11
// 12
// 13
// 14

View file

@ -0,0 +1 @@
varar(1, "bla", 5, "end");

View file

@ -0,0 +1,3 @@
local runtime_array = {1, "bla", 5, "end"};
varar(unpack(runtime_array));

View file

@ -0,0 +1 @@
call(f, v)

View file

@ -1,4 +1,4 @@
call print_all .1,5,2,4,-3, 4.7e1, 013.000 ,, 8**2 -3, sign(-66), abs(-71.00), 8 || 6, 'seven numbers are prime, 8th is null'
call print_all .1,5,2,4,-3, 4.7e1, 013.000 ,, 8**2 -3, sign(-66), abs(-71.00), 8 || 9, 'seven numbers are prime, 8th is null'
call print_all "One ringy-dingy,",
"two ringy-dingy,",