UserDefinedMethod type
Methods
- ==(a:UserDefinedMethod, b:UserDefinedMethod)
Compare closures. Implemented as sameness comparison. Example
F make_closure() { F(x) x + 1 }; make_closure() == make_closure() # false - different objects F make_closure() { F(x) x + 1 }; make_closure().ip() == make_closure().ip() # true - same code f = F(x) x +1; f == f # true - same instance
- ArgvMatcher(option:Str, value:Any, f:UserDefinedMethod) Source: autoload/ArgvMatcher.ngs:30
Sets ARGV matching option. Parameters
option Option name. The only supported option at this time is "positionals". value Option value. Example
# Any command line argument that is not "allreg" goes to "filters" parameters. ArgvMatcher('positionals', 'filters') do F main(filters:Arr, allreg:Bool=false) ...
- c_pthread_create(attr:c_pthread_attr_t, start_routine:UserDefinedMethod, arg:Any)
Call PTHREAD_CREATE(3). Not recommended for direct calls, use Thread type instead. Returns
Arr with [Int, c_pthread_t]. Int is the status returned by pthread_create(). c_pthread_t is a thin wrapper around underlying pthread_t, returned by PTHREAD_CREATE(3)Example
F init(t:Thread, f:Fun, arg) { thread_attr = c_pthread_attr_t() c_pthread_attr_init(thread_attr) create_result = c_pthread_create(thread_attr, f, arg) code = create_result[0] if code { throw Error("Failed to c_pthread_create") } t.thread = create_result[1] }
- ip(c:UserDefinedMethod)
Get closure code instruction pointer. Returns
IntExample
f=F(x) x+1; f.ip() # 116506
- params(c:UserDefinedMethod)
Introspect closure parameters. Example
... F the_one(something, predicate, body:Fun, found_more:Fun={null}, found_none:Fun={null}) ... the_one.Arr()[1].params().each(echo)# {name=something, type=<Type Any>} # {name=predicate, type=<Type Any>} # {name=body, type=<Type Fun>} # {name=found_more, type=<Type Fun>, dflt=<UserDefinedMethod <anonymous> at /usr/share/ngs/stdlib.ngs:198>} # {name=found_none, type=<Type Fun>, dflt=<UserDefinedMethod <anonymous> at /usr/share/ngs/stdlib.ngs:198>}
- push(hook:Hook, handler:UserDefinedMethod) Source: stdlib.ngs:783
Add unnamed handler. The hook is automatically named "pushed-N" where N is sequential integer. Returns
New hook name
- Str(c:UserDefinedMethod) Source: stdlib.ngs:846
String representation of a closure Returns
StrExample
Real.constructors[-1].Str().echo() # Outputs: <UserDefinedMethod Real at /usr/share/ngs/stdlib.ngs:350>
- ~(argv:Arr, udm:UserDefinedMethod) Source: autoload/ArgvMatcher.ngs:51
Please do not use directly! Tries to match command line arguments with closure parameters. Parameters
argv Command line arguments, typically ARGV udm UserDefinedMethod to match with Returns
Match (ParamsMatchY on success, ParamsMatchN on failure). If ParamsMatchY is returned it has "matches" field with values in suitable order to call c. If ParamsMatchN is returned, it has "message" field explaining why there was no match. Currently it's not printed anywhere.Example
ArgvMatcher; (["--b", "B", "A", "C"] ~ F(a,b,c) 7).matches # %[A B C] (["A", "C", "D", "--b", "B"] ~ ArgvMatcher("positionals", "a") do F(a,b) 7).matches # %[%[A C D] B]