Procs
proc `<`(v, w: Value): bool {....raises: [KeyError, Exception], tags: [].}
- checks whether the v is smaller than w Note: this is only defined for a subset of the possible types! Note2: if both are numbers of different kind (VInt and VFloat) the values are compared as a float! For very large values this would be problematic, but here we are lenient and assume the user uses Value for small calculations! Source Edit
proc `==`(v, w: Value): bool {....raises: [KeyError], tags: [].}
- checks whether the values are equal. Note: if both values are numbers of different kind (VInt and VFloat) the values are both compared as floats! The float comparison happens with a floating point comparison with relatively large epsilon (1-e8). Source Edit
func almostEqual(a, b: float; epsilon = 1e-8): bool {....raises: [], tags: [].}
- Source Edit
func isNumber(s: string): bool {....raises: [], tags: [].}
-
returns true, if s is a number according to our rules:
- starts with {0..9}
- ends with {0..9}
- may contain a single .
- may contain a single e, E
- may contain one minus, one plus at beginning and one for exponent
- else may only contain {0..9}
- e, +, -, . may not appear one after another
- may contain space before and after the number
It is only used to decide whether the stringifaction of s will be surrounded by ".
Source Edit proc largerOrFalse(v: Value; f: float): bool {.inline, ...raises: [], tags: [].}
- extension of < for Value to return false if v is not a valid VInt/VFloat. Source Edit
proc newVObject(length = 8): Value {....raises: [], tags: [].}
- Source Edit
proc pretty(v: Value; precision = 4; emphStrNumber = true): string {. ...raises: [ValueError], tags: [].}
- converts the given value to its value as a string. For VFloat the precision can be given. If emphStrNumber is true, a number stored as a string will be emphasized by enclosing it with explicit ". This is mainly for printing DFs to show the user if a number is a number or a string. Source Edit
proc smallerOrFalse(v: Value; f: float): bool {.inline, ...raises: [], tags: [].}
- extension of < for Value to return false if v is not a valid VInt/VFloat. Source Edit
proc toStr(v: Value): string {....raises: [Exception, ValueError], tags: [RootEffect].}
-
Returns the value v as a string. If the value is of kind VString, no conversion is required. This however will fail, if the input is of type
- VNull
- VObject
if you want string representations of those value types, use $
Source Edit
Templates
template convenienceValueComparisons(): untyped
-
These are a few comparison procedures that are defined for convenience within the context of a f{} formula to allow writing foo == "bar" even if foo is actually a Value based column.
This is handled by simply inserting these templates into the closure body.
Feel free to call the template in a local (or global) scope to make them available in other scopes. Note that the templates are not exported!
Source Edit template withNative(v: Value; valName: untyped; body: untyped): untyped
- Source Edit
template withNativeConversion(kind: ValueKind; procName: untyped; body: untyped): untyped
- generates an environment, in which the correct to* proc is named procName for kind Source Edit