Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,15 @@
|
|||
;; wrong - make-vector is evaluated one time - same vector
|
||||
|
||||
(define L (make-list 3 (make-vector 4)))
|
||||
L → (#(0 0 0 0) #(0 0 0 0) #(0 0 0 0))
|
||||
(vector-set! (first L ) 1 '🔴) ;; sets the 'first' vector
|
||||
|
||||
L → (#(0 🔴 0 0) #(0 🔴 0 0) #(0 🔴 0 0))
|
||||
|
||||
;; right - three different vectors
|
||||
|
||||
(define L(map make-vector (make-list 3 4)))
|
||||
L → (#(0 0 0 0) #(0 0 0 0) #(0 0 0 0))
|
||||
(vector-set! (first L ) 1 '🔵) ;; sets the first vector
|
||||
|
||||
L → (#(0 🔵 0 0) #(0 0 0 0) #(0 0 0 0)) ;; OK
|
||||
|
|
@ -0,0 +1 @@
|
|||
{ [foo()] * n }
|
||||
|
|
@ -0,0 +1 @@
|
|||
{ foo * n }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
proc foo(): string =
|
||||
echo "Foo()"
|
||||
"mystring"
|
||||
|
||||
let n = 100
|
||||
var ws = newSeq[string](n)
|
||||
for i in 0 .. <n: ws[i] = foo()
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
proc newSeqWith[T](len: int, init: T): seq[T] =
|
||||
result = newSeq[T] len
|
||||
for i in 0 .. <len:
|
||||
result[i] = init
|
||||
|
||||
var xs = newSeqWith(n, foo())
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
template newSeqWith2(len: int, init: expr): expr =
|
||||
var result {.gensym.} = newSeq[type(init)](len)
|
||||
for i in 0 .. <len:
|
||||
result[i] = init
|
||||
result
|
||||
|
||||
var ys = newSeqWith2(n, foo())
|
||||
|
|
@ -0,0 +1 @@
|
|||
ListBuffer init(10, #[ Float rand ]) println
|
||||
|
|
@ -0,0 +1 @@
|
|||
ListBuffer initValue(10, Float rand) println
|
||||
|
|
@ -0,0 +1 @@
|
|||
[Foo.new] * n; # incorrect (only one distinct object is created)
|
||||
|
|
@ -0,0 +1 @@
|
|||
n.of {Foo.new}; # correct
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
class Foo { }
|
||||
|
||||
var foos = [Foo]()
|
||||
for i in 0..<n {
|
||||
foos.append(Foo())
|
||||
}
|
||||
|
||||
// incorrect version:
|
||||
var foos_WRONG = [Foo](count: n, repeatedValue: Foo()) // Foo() only evaluated once
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
def Array(atype; n):
|
||||
if atype == "number" then [ range(0;n) ]
|
||||
elif atype == "object" then [ range(0;n)| {"value": . } ]
|
||||
elif atype == "array" then [ range(0;n)| [.] ]
|
||||
elif atype == "string" then [ range(0;n)| tostring ]
|
||||
elif atype == "boolean" then
|
||||
if n == 0 then [] elif n == 1 then [false] elif n==2 then [false, true]
|
||||
else error("there are only two boolean values")
|
||||
end
|
||||
elif atype == "null" then
|
||||
if n == 0 then [] elif n == 1 then [null]
|
||||
else error("there is only one null value")
|
||||
end
|
||||
else error("\(atype) is not a jq type")
|
||||
end;
|
||||
|
||||
# Example:
|
||||
|
||||
Array("object"; 4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue