routines
TLDR
- routine: a symbol of kind proc, func, method, iterator, macro, template, converter
- IMO this definition should also include tasks
- where to find which
- converters in globalVariables
- iterators in loopsIterators
- lambdas in sugar
- std & nimscript tasks in packaging
- templates in templateMacros
- other routine types are in this file
- routine exception tracking is in pragmasEffects
gotchas
- read this if you receive `cant instantiate result/generic/etc`
- basically you need provide type params at callsite as for the generic your invoking
links
TODOs
- offsetOf
- rangeCheck(cond)
- forward directions, couldnt get it to compile
- read the status docs on this one
- something to do with long lived ref objects & unreclaimable memory
procedures
- returning things: (cant contain a yield statement)
- use return keyword for early returns
- result = sumExpression: enables return value optimization & copy elision
- if return/result isnt used last expression's value is returned
- overload: redeclare with different signature
- args passed to procs are eagerly evaluated
- see templates for lazy evaluation
openArray
- openArrayT implemented as a pointer to the array data and a length field
- only used in proc signatures for accepting an array of any length
- cant be used to with multidimensional array arguments
- always index with int and starting at 0
- array args must match the param base type, index type is ignored
- arrays and seqs are implicity converted for openArray params
varargs
- enables passing a variable number of args to a proc param
- the args are converted to an array if the param is the last param
funcs
- alias for {. noSideEffect .}
- compiler throws error if reading/writing to global variables
- i.e. any var not a parameter/local
- allocating a seq/string does not throw an err
closures
- can be created with proc expressions or do notation
anonymous procs
- dont have a name and surrounded by paranthesis
Procs
proc communicate(greeting: proc (x: string): string; name: string) {. ...raises: [Exception], tags: [RootEffect], forbids: [].}
- Source Edit
proc copyThenMutateValue(x: string): void {....raises: [], tags: [], forbids: [].}
- Source Edit
proc ekoAnything(s: varargs[string, `$`]) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc openArraySize(oa: openArray[string]): int {....raises: [], tags: [], forbids: [].}
- Source Edit
proc passedByReference(yy: var string): void {....raises: [], tags: [], forbids: [].}
- Source Edit
proc passedByValue(x: string): void {....raises: [], tags: [], forbids: [].}
- Source Edit
proc writeAccessToG(): var int {....raises: [], tags: [], forbids: [].}
- Source Edit