-
-
Save ReneSac/3b56d3b3836761093436 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const | |
| NumCoord = 3 | |
| maxpts = 8 | |
| type | |
| TPt = object # A particle object: | |
| p, v : array[NumCoord, float64] # The position and velocity. | |
| r, life: float64 # Radius and remaining lifetime | |
| bis: bool # Living or not | |
| Tpts = object | |
| high, low: int # The maximum index in the pool that currently contains a particle | |
| pool: array[MaxPts, TPt] # The pool of particles | |
| proc `[]`(pts: var Tpts, key: int): TPt = pts.pool[key] | |
| proc `[]=`(pts: var Tpts, key: int, val: TPt) = pts.pool[key] = val | |
| var pts = Tpts(high: 0, low: 0) | |
| pts[1].life = 4 | |
| echo repr pts[1] | |
| # Compilation result: Error: '[](pts, 1).life' cannot be assigned to | |
| # If I take off the 'var' from the first parameter, then the error is: Error: 'pts.pool[key]' cannot be assigned to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It was just the lack of 'var' on the return variable from
[]. It seems I don't even need to define[]=