NormalTypeInstance type
Methods
- .(obj:NormalTypeInstance, field:Str)
Get NormalType (a type that is typically defined by user) instance field. Throws FieldNotFound. Automatically called by NGS for syntax
obj.field
Returns
AnyExample
type T; t=T(); t.x=1; t.x # 1
- .=(obj:NormalTypeInstance, field:Str, v:Any)
Set Normal type (a type that is typically defined by user) instance field Automatically called by NGS for syntax
obj.field = v
Returns
vExample
type T; t=T(); t.x=1
- ::(nti:NormalTypeInstance, k:Any) Source: stdlib.ngs:352
Get NormalType object field. Useful when calling method stored in an field. Example
myobj::method_in_field(arg) # calls method stored in myobj.method_in_field (myobj.method_in_field)(arg) # calls method stored in myobj.method_in_field myobj.method_in_field(arg) # calls global "method_in_field"
- ::=(nti:NormalTypeInstance, k:Any, v:Any) Source: stdlib.ngs:361
Set NormalType object field. It's implemented to complete the :: operator. There is no particular use case.
- ==(a:NormalTypeInstance, b:NormalTypeInstance) Source: stdlib.ngs:820
Equality test for normal type instances: must be of same type and have same fields and their values Returns
BoolExample
type T t1 = T() t1.a = 1 t2 = T() t2.a = 1 echo(t1 == t2) # Outputs: true
- copy(nti:NormalTypeInstance) Source: stdlib.ngs:803
Make shallow copy of an object
- dflt(i:NormalTypeInstance, k:Any, v:Any) Source: stdlib.ngs:792
Set object field if it's not already set Returns
Field value, the already-existed or new.Example
my_something.dflt(k, []).push(elt)
- Hash(obj:NormalTypeInstance)
Get all fields and their values as key-value pairs in the resulting Hash. Returns
HashExample
(1..10).Hash() # Hash {start=1, end=10, step=1}
- in(field:Str, obj:NormalTypeInstance)
Check whether NormalType (a type that is typically defined by user) instance has the given field. Automatically called by NGS for syntax
field in obj
Returns
BoolExample
type T; t=T(); t.x=1; "x" in t # true
- Str(i:NormalTypeInstance) Source: stdlib.ngs:773
String representation of normal type instance i Normal type is a user defined type. In addition some types defined by NGS are also normal types. Returns
"<TYPE_NAME field1=val1 field2=val2 ...>"Example
{ type T # nti - Normal type instance nti = T() nti.a = 1 nti.b = 2 echo(Str(nti)) # <T a=1 b=2> }