mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 12:54:22 +00:00
implemented 'koch pdf'
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
discard """
|
||||
line: 12
|
||||
errormsg: "type mismatch: got (proc (int){.closure, gcsafe.})"
|
||||
errormsg: "type mismatch: got (proc (int){.closure, gcsafe, locks: 0.})"
|
||||
"""
|
||||
|
||||
proc ugh[T](x: T) {.closure.} =
|
||||
echo "ugha"
|
||||
|
||||
|
||||
proc takeCdecl(p: proc (x: int) {.cdecl.}) = nil
|
||||
proc takeCdecl(p: proc (x: int) {.cdecl.}) = discard
|
||||
|
||||
takeCDecl(ugh[int])
|
||||
|
||||
@@ -11,6 +11,6 @@ import sets
|
||||
|
||||
var intset = initSet[int]()
|
||||
|
||||
proc func*[T](a: T) =
|
||||
proc fn*[T](a: T) =
|
||||
if a in intset: echo("true")
|
||||
else: echo("false")
|
||||
|
||||
@@ -7,4 +7,4 @@ import mdotlookup
|
||||
|
||||
foo(7)
|
||||
# bug #1444
|
||||
func(4)
|
||||
fn(4)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
discard """
|
||||
output: "1.1000000000000001e+00 11"
|
||||
ccodecheck: "!@'ClEnv'"
|
||||
disabled: "true"
|
||||
"""
|
||||
|
||||
proc p[T](a, b: T): T
|
||||
|
||||
@@ -8,22 +8,22 @@ type
|
||||
b: proc(val: T) {.thread.}
|
||||
|
||||
proc handleThreadFunc(arg: TThreadFuncArgs[int]){.thread.} =
|
||||
var func = arg.a
|
||||
var fn = arg.a
|
||||
var callback = arg.b
|
||||
var output = func()
|
||||
var output = fn()
|
||||
callback(output)
|
||||
|
||||
proc `@||->`*[T](func: proc(): T {.thread.},
|
||||
proc `@||->`*[T](fn: proc(): T {.thread.},
|
||||
callback: proc(val: T){.thread.}): TThread[TThreadFuncArgs[T]] =
|
||||
var thr: TThread[TThreadFuncArgs[T]]
|
||||
var args: TThreadFuncArgs[T]
|
||||
args.a = func
|
||||
args.a = fn
|
||||
args.b = callback
|
||||
createThread(thr, handleThreadFunc, args)
|
||||
return thr
|
||||
|
||||
proc `||->`*[T](func: proc(): T{.thread.}, callback: proc(val: T){.thread.}) =
|
||||
discard func @||-> callback
|
||||
proc `||->`*[T](fn: proc(): T{.thread.}, callback: proc(val: T){.thread.}) =
|
||||
discard fn @||-> callback
|
||||
|
||||
when isMainModule:
|
||||
import os
|
||||
|
||||
@@ -35,9 +35,9 @@ echo noParams(() => 3)
|
||||
|
||||
echo doWithOneAndTwo((x, y) => x + y)
|
||||
|
||||
noReturn(() -> void => echo("noReturn"))
|
||||
noReturn((() -> void) => echo("noReturn"))
|
||||
|
||||
proc pass2(f: (int, int) -> int): (int) -> int =
|
||||
(x: int) -> int => f(2, x)
|
||||
((x: int) -> int) => f(2, x)
|
||||
|
||||
echo pass2((x, y) => x + y)(4)
|
||||
Reference in New Issue
Block a user