Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,19 +1,27 @@
|
|||
program Project1;
|
||||
|
||||
type
|
||||
TFuncIntResult = reference to function : integer;
|
||||
TFuncIntResult = reference to function: Integer;
|
||||
|
||||
// use function that returns anonymous method to avoid capturing the loop variable
|
||||
function CreateFunc(i: Integer): TFuncIntResult;
|
||||
begin
|
||||
Result :=
|
||||
function: Integer
|
||||
begin
|
||||
Result := i * i;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
Funcs : array [0..9] of TFuncIntResult;
|
||||
i : integer;
|
||||
|
||||
Funcs: array[0..9] of TFuncIntResult;
|
||||
i: integer;
|
||||
begin
|
||||
// Create 10 anonymous functions
|
||||
// create 10 anonymous functions
|
||||
for i := Low(Funcs) to High(Funcs) do
|
||||
Funcs[i] := function() : integer begin Result := i*i; end;
|
||||
Funcs[i] := CreateFunc(i);
|
||||
|
||||
// call all 10 functions
|
||||
for i := Low(Funcs) to High(Funcs) do
|
||||
writeln( Funcs[i]() );
|
||||
|
||||
Writeln(Funcs[i]());
|
||||
end.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
#lang racket
|
||||
(map (λ(f) (f))
|
||||
(for/list ([i 10]) (λ () (* i i))))
|
||||
(define functions (for/list ([i 10]) (λ() (* i i))))
|
||||
(map (λ(f) (f)) functions)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
fn main() {
|
||||
let fs: ~[proc() -> uint] = range(0u,10).map(|i| {proc() i*i}).collect();
|
||||
println!("7th val: {}", fs[7]());
|
||||
let fs: Vec<_> = (0..10).map(|i| {move || i*i} ).collect();
|
||||
println!("7th val: {}", fs[7]());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
(build-list-of-functions n (+ i 1) (cons (lambda () (* (- n i) (- n i))) list))
|
||||
list))
|
||||
|
||||
(define list-of-functions (build-list-of-functions 11 1 '()))
|
||||
(define list-of-functions (build-list-of-functions 10 1 '()))
|
||||
|
||||
(map (lambda (f) (f)) list-of-functions)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
(1 4 9 16 25 36 49 64 81 100)
|
||||
'(1 4 9 16 25 36 49 64 81)
|
||||
81
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
(define list-of-functions (map (lambda (x) (lambda () (* x x))) (iota 0 1 10)))
|
||||
|
||||
; print the result
|
||||
(display
|
||||
(map (lambda (n) (n)) list-of-functions)
|
||||
(newline)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(let ((funs (mapcar (ret (op * @@1 @@1)) (range 1 10))))
|
||||
[mapcar call [funs 0..-1]])
|
||||
|
|
@ -0,0 +1 @@
|
|||
(1 4 9 16 25 36 49 64 81)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
;; Dropping distracting "skip last" requirement
|
||||
;; (not implemented in original Elisp either).
|
||||
(mapcar 'call
|
||||
(mapcar (lambda ()
|
||||
(lambda () (* x x))) '(1 2 3 4 5 6 7 8 9 10)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue