Multiple distinct objects: Difference between revisions

added scheme example
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
(added scheme example)
Line 1,044:
 
<lang scala>for (i <- (0 until n)) yield new Foo()</lang>
 
=={{header|Scheme}}==
{{libheader|Scheme/SRFIs}}
 
There is a standard function make-list which makes a list of size n, but repeats its given value.
 
<pre>
sash[r7rs]> (define-record-type <a> (make-a x) a? (x get-x))
#<unspecified>
sash[r7rs]> (define l1 (make-list 5 (make-a 3)))
#<unspecified>
sash[r7rs]> (eq? (list-ref l1 0) (list-ref l1 1))
#t
</pre>
 
In SRFI 1, a function list-tabulate is provided which instead calls a function to create a fresh value each time.
 
<pre>
sash[r7rs]> (define l2 (list-tabulate 5 (lambda (i) (make-a i))))
#<unspecified>
sash[r7rs]> (eq? (list-ref l2 0) (list-ref l2 1))
#f
sash[r7rs]> (map get-x l2)
(0 1 2 3 4)
</pre>
 
 
=={{header|Seed7}}==
342

edits