September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,24 @@
|
|||
* Loop over multiple arrays simultaneously 09/03/2017
|
||||
LOOPSIM CSECT
|
||||
USING LOOPSIM,R12 base register
|
||||
LR R12,R15
|
||||
LA R6,1 i=1
|
||||
LA R7,3 counter=3
|
||||
LOOP LR R1,R6 i
|
||||
SLA R1,1 *2
|
||||
LH R2,R-2(R1) r(i)
|
||||
XDECO R2,PG edit r(i)
|
||||
LA R1,S-1(R6) @s(i)
|
||||
MVC PG+3(1),0(R1) output s(i)
|
||||
LA R1,Q-1(R6) @q(i)
|
||||
MVC PG+7(1),0(R1) output q(i)
|
||||
XPRNT PG,80 print s(i),q(i),r(i)
|
||||
LA R6,1(R6) i++
|
||||
BCT R7,LOOP decrement and loop
|
||||
BR R14 exit
|
||||
S DC C'a',C'b',C'c'
|
||||
Q DC C'A',C'B',C'C'
|
||||
R DC H'1',H'2',H'3'
|
||||
PG DC CL80' ' buffer
|
||||
YREGS
|
||||
END LOOPSIM
|
||||
|
|
@ -1,61 +1,63 @@
|
|||
-- ZIP LISTS WITH FUNCTION ---------------------------------------------------
|
||||
|
||||
-- zipListsWith :: ([a] -> b) -> [[a]] -> [[b]]
|
||||
on zipListsWith(f, xss)
|
||||
set lngLists to length of xss
|
||||
set n to length of xss
|
||||
|
||||
-- appliedToNths :: a -> Int -> [b]
|
||||
script appliedToNths
|
||||
on lambda(_, i)
|
||||
-- nthItem :: [a] -> a
|
||||
script nthItem
|
||||
on lambda(xs)
|
||||
script
|
||||
on |λ|(_, i)
|
||||
script
|
||||
on |λ|(xs)
|
||||
item i of xs
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
if i ≤ lngLists then
|
||||
apply(f, (map(nthItem, xss)))
|
||||
if i ≤ n then
|
||||
apply(f, (map(result, xss)))
|
||||
else
|
||||
{}
|
||||
end if
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
if lngLists > 0 then
|
||||
map(appliedToNths, item 1 of xss)
|
||||
if n > 0 then
|
||||
map(result, item 1 of xss)
|
||||
else
|
||||
[]
|
||||
end if
|
||||
end zipListsWith
|
||||
|
||||
|
||||
|
||||
-- TEST
|
||||
|
||||
-- Function to apply:
|
||||
|
||||
-- concatList [String] -> String
|
||||
on concatList(lst)
|
||||
intercalate("", lst)
|
||||
end concatList
|
||||
|
||||
-- TEST ( zip lists with concat ) -------------------------------------------
|
||||
on run
|
||||
-- Application:
|
||||
|
||||
intercalate(linefeed, ¬
|
||||
zipListsWith(concatList, ¬
|
||||
zipListsWith(concat, ¬
|
||||
[["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]]))
|
||||
|
||||
end run
|
||||
|
||||
|
||||
|
||||
-- GENERIC FUNCTIONS
|
||||
-- GENERIC FUNCTIONS ---------------------------------------------------------
|
||||
|
||||
-- apply (a -> b) -> a -> b
|
||||
on apply(f, a)
|
||||
mReturn(f)'s lambda(a)
|
||||
mReturn(f)'s |λ|(a)
|
||||
end apply
|
||||
|
||||
-- concat :: [[a]] -> [a] | [String] -> String
|
||||
on concat(xs)
|
||||
if length of xs > 0 and class of (item 1 of xs) is string then
|
||||
set acc to ""
|
||||
else
|
||||
set acc to {}
|
||||
end if
|
||||
repeat with i from 1 to length of xs
|
||||
set acc to acc & item i of xs
|
||||
end repeat
|
||||
acc
|
||||
end concat
|
||||
|
||||
-- intercalate :: Text -> [Text] -> Text
|
||||
on intercalate(strText, lstText)
|
||||
set {dlm, my text item delimiters} to {my text item delimiters, strText}
|
||||
|
|
@ -70,7 +72,7 @@ on map(f, xs)
|
|||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to lambda(item i of xs, i, xs)
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
|
|
@ -83,7 +85,7 @@ on mReturn(f)
|
|||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
char a1[] = {'a','b','c'};
|
||||
char a2[] = {'A','B','C'};
|
||||
int a3[] = {1,2,3};
|
||||
|
||||
int main(void) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
printf("%c%c%i\n", a1[i], a2[i], a3[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
typedef struct closure {
|
||||
void (*f)( void *elem, void *data);
|
||||
void *data;
|
||||
} *Closure;
|
||||
|
||||
typedef struct listSpec{
|
||||
void (*print)(const void *);
|
||||
void *ary;
|
||||
int count;
|
||||
size_t elem_size;
|
||||
} *ListSpec;
|
||||
|
||||
#define LIST_SPEC( pf,typ,aa) {pf, aa, (sizeof(aa)/sizeof(typ)), sizeof(typ) }
|
||||
|
||||
|
||||
/* calls closure's function f for each element in list */
|
||||
void DoForEach( Closure c, ListSpec aspec )
|
||||
{
|
||||
int i;
|
||||
void *val_ptr;
|
||||
for (i=0, val_ptr=aspec->ary; i< aspec->count; i++) {
|
||||
(*c->f)(val_ptr, c->data);
|
||||
val_ptr = ((char *)val_ptr) + aspec->elem_size;
|
||||
}
|
||||
}
|
||||
|
||||
/* Used to find the minimum array length of list of lists */
|
||||
void FindMin( ListSpec *paspec, int *minCount )
|
||||
{
|
||||
ListSpec aspec = *paspec;
|
||||
if (*minCount>aspec->count) *minCount = aspec->count;
|
||||
}
|
||||
|
||||
/* prints an element of a list using the list's print function */
|
||||
void PrintElement( ListSpec *paspec, int *indx )
|
||||
{
|
||||
ListSpec aspec = *paspec;
|
||||
(*aspec->print)( ((char*)aspec->ary) + (*indx)*aspec->elem_size);
|
||||
}
|
||||
|
||||
|
||||
/* Loop Over multiple lists (a list of lists)*/
|
||||
void LoopMultiple( ListSpec arrays)
|
||||
{
|
||||
int indx;
|
||||
int minCount = 100000;
|
||||
struct closure c1 = { &FindMin, &minCount };
|
||||
struct closure xclsr = { &PrintElement, &indx };
|
||||
DoForEach( &c1, arrays);
|
||||
printf("min count = %d\n", minCount);
|
||||
|
||||
for (indx=0; indx<minCount; indx++) {
|
||||
DoForEach(&xclsr, arrays );
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* Defining our Lists */
|
||||
|
||||
void PrintInt(const int *ival)
|
||||
{ printf("%3d,", *ival);
|
||||
}
|
||||
int ary1[] = { 6,5,4,9,8,7 };
|
||||
struct listSpec lspec1 = LIST_SPEC( &PrintInt, int, ary1 );
|
||||
|
||||
void PrintShort(const short *ival)
|
||||
{ printf("%3d,", *ival);
|
||||
}
|
||||
short ary2[] = { 3, 66, 20, 15, 7, 22, 10 };
|
||||
struct listSpec lspec2 = LIST_SPEC( &PrintShort , short, ary2 );
|
||||
|
||||
void PrintStrg(const char *const *strg )
|
||||
{ printf(" %s", *strg);
|
||||
}
|
||||
const char *ary3[] = {"Hello", "all", "you","good", "folks","out", "there" };
|
||||
struct listSpec lspec3 = LIST_SPEC( &PrintStrg , const char *, ary3 );
|
||||
|
||||
void PrintLstSpec(const ListSpec *ls)
|
||||
{ printf("not-implemented");
|
||||
}
|
||||
ListSpec listList[] = { &lspec1, &lspec2, &lspec3 };
|
||||
struct listSpec llSpec = LIST_SPEC(&PrintLstSpec, ListSpec, listList);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
LoopMultiple( &llSpec);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,16 +1,14 @@
|
|||
#import system.
|
||||
import extensions.
|
||||
|
||||
#symbol program =
|
||||
program =
|
||||
[
|
||||
#var a1 := ("a","b","c").
|
||||
#var a2 := ("A","B","C").
|
||||
#var a3 := (1,2,3).
|
||||
var a1 := ("a","b","c").
|
||||
var a2 := ("A","B","C").
|
||||
var a3 := (1,2,3).
|
||||
|
||||
#var i := Integer new:0.
|
||||
#loop (i < a1 length)?
|
||||
0 till(a1 length) do(:i)
|
||||
[
|
||||
console writeLine:(a1@i + a2@i + (a3@i) literal).
|
||||
i := i + 1.
|
||||
console printLine(a1[i], a2[i], a3[i]).
|
||||
].
|
||||
|
||||
console readChar.
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
#import system.
|
||||
#import system'routines.
|
||||
import system'routines.
|
||||
import extensions.
|
||||
|
||||
#symbol program =
|
||||
program =
|
||||
[
|
||||
#var a1 := ("a","b","c").
|
||||
#var a2 := ("A","B","C").
|
||||
#var a3 := (1,2,3).
|
||||
#var zipped := (a1 zip: a2 &into:(:first:second) [ first + second ])
|
||||
zip: a3 &into:(:first:second) [ first + (second literal)].
|
||||
var a1 := ("a","b","c").
|
||||
var a2 := ("A","B","C").
|
||||
var a3 := (1,2,3).
|
||||
var zipped := a1 zip:a2 by(:first:second)( first + second );
|
||||
zip:a3 by(:first:second)( first + second literal ).
|
||||
|
||||
zipped run &each: e
|
||||
zipped forEach(:e)
|
||||
[ console writeLine:e. ].
|
||||
|
||||
console readChar.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
Public Sub Main()
|
||||
Dim a1 As String[] = ["a", "b", "c"]
|
||||
Dim a2 As String[] = ["A", "B", "C"]
|
||||
Dim a3 As String[] = ["1", "2", "3"]
|
||||
Dim siC As Short
|
||||
|
||||
For siC = 0 To a1.Max
|
||||
Print a1[siC] & a2[siC] & a3[siC]
|
||||
Next
|
||||
|
||||
End
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
("aA1"
|
||||
"bB2"
|
||||
"cC3")
|
||||
|
|
@ -1 +0,0 @@
|
|||
{a:,/'($:'x);+a[;!(&/#:'a)]}("abc";"ABC";1 2 3 4)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
// version 1.0.6
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a1 = charArrayOf('a', 'b', 'c')
|
||||
val a2 = charArrayOf('A', 'B', 'C')
|
||||
val a3 = intArrayOf(1, 2, 3)
|
||||
for(i in 0 .. 2) println("${a1[i]}${a2[i]}${a3[i]}")
|
||||
println()
|
||||
// For arrays of different sizes we would need to iterate up to the mimimm size of all 3 in order
|
||||
// to get a contribution from each one.
|
||||
val a4 = intArrayOf(4, 5, 6, 7)
|
||||
val a5 = charArrayOf('d', 'e')
|
||||
val minSize = Math.min(a2.size, Math.min(a4.size, a5.size)) // minimum size of a2, a4 and a5
|
||||
for(i in 0 until minSize) println("${a2[i]}${a4[i]}${a5[i]}")
|
||||
}
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
a1, a2, a3 = {a , b , c } , { A , B , C } , { 1 , 2 , 3 }
|
||||
for i = 1, 3 do print(a1[i],a2[i],a3[i]) end
|
||||
a1, a2, a3 = {'a' , 'b' , 'c' } , { 'A' , 'B' , 'C' } , { 1 , 2 , 3 }
|
||||
for i = 1, 3 do print(a1[i]..a2[i]..a3[i]) end
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@ function iter(a, b, c)
|
|||
end
|
||||
end
|
||||
|
||||
for u, v, w in iter(a1, a2, a3) do print(u, v, w) end
|
||||
for u, v, w in iter(a1, a2, a3) do print(u..v..w) end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
x = .array~of("a", "b", "c")
|
||||
y = .array~of("A", "B", "C")
|
||||
z = .array~of(1, 2, 3)
|
||||
|
||||
loop i = 1 to x~size
|
||||
say x[i]y[i]z[i]
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
declare P(3) character (1) initial ('a', b', 'c'),
|
||||
declare P(3) character (1) initial ('a', 'b', 'c'),
|
||||
Q(3) character (1) initial ('A', 'B', 'C'),
|
||||
R(3) fixed decimal (1) initial (1, 2, 3);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
local u a b c
|
||||
local v A B C
|
||||
matrix w=1,2,3
|
||||
forv i=1/3 {
|
||||
di "`: word `i' of `u''`: word `i' of `v''`=el("w",1,`i')'"
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
mata
|
||||
u="a","b","c"
|
||||
v="A","B","C"
|
||||
w=1,2,3
|
||||
|
||||
for (i=1; i<=3; i++) {
|
||||
printf("%s%s%f\n",u[i],v[i],w[i])
|
||||
}
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
foreach a,b,c in (["a".."c"].zip(T("A","B","C"),[1..])){ println(a,b,c) }
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Utils.zipWith(False,fcn{vm.arglist.concat().println()},
|
||||
["a".."c"],T("A","B","C"),[1..])
|
||||
Loading…
Add table
Add a link
Reference in a new issue