September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,18 +1,18 @@
import system'routines.
import extensions.
import system'routines;
import extensions;
extension variadicOp
{
generic printAll(object<> list)
[
list forEach(:v)
[
self printLine:v
]
]
printAll(params object[] list)
{
list.forEach:(v)
{
self.printLine:v
}
}
}
program =
[
console printAll("test", "rosetta code", 123, 5.6r).
].
public program()
{
console.printAll("test", "rosetta code", 123, 5.6r)
}

View file

@ -0,0 +1,39 @@
program variadicRoutinesDemo(input, output, stdErr);
{$mode objFPC}
// array of const is only supported in $mode objFPC or $mode Delphi
procedure writeLines(const arguments: array of const);
var
argument: TVarRec;
begin
// inside the body `array of const` is equivalent to `array of TVarRec`
for argument in arguments do
begin
with argument do
begin
case vType of
vtInteger:
begin
writeLn(vInteger);
end;
vtBoolean:
begin
writeLn(vBoolean);
end;
vtChar:
begin
writeLn(vChar);
end;
vtAnsiString:
begin
writeLn(ansiString(vAnsiString));
end;
// and so on
end;
end;
end;
end;
begin
writeLines([42, 'is', true, #33]);
end.

View file

@ -0,0 +1,4 @@
42
is
TRUE
!

View file

@ -0,0 +1,24 @@
#!/usr/bin/env golosh
----
This module demonstrates variadic functions.
----
module Variadic
import gololang.Functions
----
Varargs have the three dots after them just like Java.
----
function varargsFunc = |args...| {
foreach arg in args {
println(arg)
}
}
function main = |args| {
varargsFunc(1, 2, 3, 4, 5, "against", "one")
# to call a variadic function with an array we use the unary function
unary(^varargsFunc)(args)
}

View file

@ -0,0 +1,7 @@
{-# LANGUAGE GADTs #-}
...
instance a ~ () => PrintAllType (IO a) where
process args = do mapM_ putStrLn args
...

View file

@ -1,5 +1,40 @@
Option Explicit
'--------------------------------------------------
Sub varargs(ParamArray a())
For n = 0 To UBound(a)
Debug.Print a(n&)
Dim n As Long, m As Long
Debug.Assert VarType(a) = (vbVariant Or vbArray)
For n = LBound(a) To UBound(a)
If IsArray(a(n)) Then
For m = LBound(a(n)) To UBound(a(n))
Debug.Print a(n)(m)
Next m
Else
Debug.Print a(n)
End If
Next
End Sub
'--------------------------------------------------
Sub Main()
Dim v As Variant
Debug.Print "call 1"
varargs 1, 2, 3
Debug.Print "call 2"
varargs 4, 5, 6, 7, 8
v = Array(9, 10, 11)
Debug.Print "call 3"
varargs v
ReDim v(0 To 2)
v(0) = 12
v(1) = 13
v(2) = 14
Debug.Print "call 4"
varargs 11, v
Debug.Print "call 5"
varargs v(2), v(1), v(0), 11
End Sub