Skip to content

Instantly share code, notes, and snippets.

@ReneSac
Last active January 4, 2016 06:59
Show Gist options
  • Save ReneSac/3b56d3b3836761093436 to your computer and use it in GitHub Desktop.
Save ReneSac/3b56d3b3836761093436 to your computer and use it in GitHub Desktop.
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
@ReneSac
Copy link
Author

ReneSac commented Jan 23, 2014

It was just the lack of 'var' on the return variable from []. It seems I don't even need to define []=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment