The most literal and direct answer to the asked question is "you don't."
More helpful but still not quite sufficient as an answer is "as function results."
Neither is completely enough when just starting out looking at things from a functional viewpoint though so let me share some things that helped me.
Functions are not methods — Functions operate on whatever is passed to them, not the 'attributes' of their 'object'. They are not bound to a thing. This is easy to grasp but equally easy to forget. In OO methods and functions are treated as synonyms.
The OO concept 'object' isn't helpful — data is a thing of its own and functions are things of their own. They are not bound together into a conceptual unit.
Data doesn't have 'properties' in the OO sense — Since your data isn't an instance it doesn't carry around details within that instance. And you probably don't want to subvert this. Doval and user39685 touch on why in their comments. I do also, below.
Looked at this way you don't really have a polyline 'class'. You have polylines as a concept and you have chosen to represent this concept as a vector of points. Since it is a vector you use it like any other vector!
If it was a vector of names and you needed how many, you'd call length. If it was a vector of airplanes and you needed how many, you'd call length, etc. all the same!
If performance is a problem then you start looking at changing the algorithm, datatype, or both. After profiling.
As user39685 said in his comment "beware of premature optimization." If it turns out you spend all your time calculating the length of points then you memoize or wrap the polyline up in a map with a :length key like you have (but think twice because now you have a special snowflake to support, see below).
If you don't rush to bundle your data up into ad-hoc objects you don't have to un-bundle to use all the primitive functions already written for you. Your functions then also tend to become smaller, simpler, and more general because you don't have to wrap and unwrap or parse and bundle data before operating on it.
length
as a method. That was my point; if you're going to considerlength
a method because it returns some info about a polyline, then so isremoveEveryThirdSegmentAndCalculateHalfTheLength
. What makeslength
special? – Doval Jul 16 '14 at 15:03length
special is its general usefulness: the frequency with which that calculation is needed and valuable. The putativerETSACHTL
method, in contrast, would essentially never be used. – Jonathan Eunice Aug 19 '14 at 21:23