Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1 +1,2 @@
|
|||
In this task, the goal is to take a combined set of elements and apply a function to each element.
|
||||
In this task, the goal is to take a combined set of elements
|
||||
and apply a function to each element.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
(defun sq-each (xs)
|
||||
(defun apply-to-each (xs)
|
||||
(if (endp xs)
|
||||
nil
|
||||
(cons (* (first xs) (first xs))
|
||||
(cons (fn-to-apply (first xs))
|
||||
(sq-each (rest xs)))))
|
||||
|
||||
(defun fn-to-apply (x)
|
||||
(* x x))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ map(list l, void (*fp) (object))
|
|||
|
||||
i = 0;
|
||||
while (i < l_length(l)) {
|
||||
fp(l_query(l, i));
|
||||
fp(l[i]);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
on callback for arg
|
||||
-- Returns a string like "arc has 3 letters"
|
||||
arg & " has " & (count arg) & " letters"
|
||||
end callback
|
||||
|
||||
set alist to {"arc", "be", "circle"}
|
||||
repeat with aref in alist
|
||||
-- Passes a reference to some item in alist
|
||||
-- to callback, then speaks the return value.
|
||||
say (callback for aref)
|
||||
end repeat
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
((main
|
||||
{ (1 1 2 3 5 8 13 21) dup
|
||||
{double !} each
|
||||
{%d ' ' . <<} each})
|
||||
|
||||
(double { dup 2 * set }))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
((main
|
||||
{ (1 1 2 3 5 8 13 21)
|
||||
{double !} each
|
||||
collect !
|
||||
{%d ' ' . <<} each})
|
||||
|
||||
(double { 2 * })
|
||||
|
||||
(collect { -1 take }))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
((main
|
||||
{ [val 1 1 2 3 5 8 13 21]
|
||||
{double !} eachar
|
||||
collect !
|
||||
{%d ' ' . <<} each})
|
||||
|
||||
(double { 2 * })
|
||||
|
||||
(collect { -1 take }))
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
( ( callbackFunction1
|
||||
= location value
|
||||
. !arg:(?location,?value)
|
||||
& out$(str$(array[ !location "] = " !!value))
|
||||
)
|
||||
& ( callbackFunction2
|
||||
= location value
|
||||
. !arg:(?location,?value)
|
||||
& !!value^2:?!value
|
||||
)
|
||||
& ( map
|
||||
= arr len callback i
|
||||
. !arg:(?arr,?len,?callback)
|
||||
& 0:?i
|
||||
& whl
|
||||
' ( !i:<!len
|
||||
& !callback$(!i,!i$!arr)
|
||||
& 1+!i:?i
|
||||
)
|
||||
)
|
||||
& tbl$(array,4)
|
||||
& 1:?(0$array)
|
||||
& 2:?(1$array)
|
||||
& 3:?(2$array)
|
||||
& 4:?(3$array)
|
||||
& map$(array,4,callbackFunction1)
|
||||
& map$(array,4,callbackFunction2)
|
||||
& map$(array,4,callbackFunction1)
|
||||
);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
$ txr -e '[mapcar prinl #(1 2 3 4 5 6 7 8 9 10)]'
|
||||
$ txr -e '[mapdo prinl #(1 2 3 4 5 6 7 8 9 10)]'
|
||||
1
|
||||
2
|
||||
3
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
echo map([10, 20, 30], 'v:val * v:val')
|
||||
echo map([10, 20, 30], '"Element " . v:key . " = " . v:val')
|
||||
echo map({"a": "foo", "b": "Bar", "c": "BaZ"}, 'toupper(v:val)')
|
||||
echo map({"a": "foo", "b": "Bar", "c": "BaZ"}, 'toupper(v:key)')
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Sin /@ {1, 2, 3, 4}
|
||||
|
||||
MapSingle(Sin, {1,2,3,4})
|
||||
|
||||
MapSingle({{x}, x^2}, {1,2,3,4})
|
||||
Loading…
Add table
Add a link
Reference in a new issue