Jonas Maebe wrote:
On 15 Apr 2013, at 16:48, Mark Morgan Lloyd wrote:

I was having a bit of fun earlier while waiting for a call. Am I correct in 
believing that something like

type    t1= array of integer;

var     a1: t1;
        x: integer;

a1 := [1,2,3,4,5];

can't be done at present, irrespective of any custom definition of the := 
operator?

Maybe if you overload the assignment operator for "t2=set of byte" to "t1" 
assignments, but I'm not certain. It's definitely not something we explicitly support.

That's a good point, although obviously ordering would be lost. After I'd tinkered with it for a while I concluded that it was probably related to the discussion of tuples a few weeks ago.

Is there an accessible not-a-number constant, to allow me to do something like

var     reduce: double= NAN;

 x := reduce + a1;

with an appropriate definition of the + operator without risk that an error 
would try to evaluate it as an ordinary arithmetic expression?

We don't have constant to identify a qNaN. I don't even know whether all 
architectures support them. Currently, the only way to achieve the above is by 
masking exceptions for invalid floating point operations: 
math.SetExceptionMask(math.GetExceptionMask + [exInvalidOp]).

Thanks, noted. In practical terms the value isn't important, and I could obviously use something like a null variant or for that matter a nil pointer as a marker.

You cannot overload/override operators that have a built-in meaning in the 
language (such as double+double).

Understood, but what I'm doing here is using "reduce +" as an experimental alternative to APL's +/ or Vector Pascal's \+ to reduce the dimension of the right operand by applying the operator:

c1:
7 9 11 13 5
+/ c1:
45

I've not investigated SSE or spreading over multiple cores yet, and probably won't due to time issues. My only incentive was looking for some alternative to Vector Pascal's higher-level functions, since obviously something like \<operator> <array> couldn't be achieved without major compiler surgery.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to