POV-Ray : Newsgroups : povray.off-topic : Unit Testing question : Re: Unit Testing question Server Time
30 Jul 2024 00:21:15 EDT (-0400)
  Re: Unit Testing question  
From: Orchid XP v8
Date: 10 Jun 2011 13:23:41
Message: <4df2531d$1@news.povray.org>
On 10/06/2011 04:49 PM, Darren New wrote:
> On 6/10/2011 8:18, Invisible wrote:
>> I think Smalltalk will also let you accidentally redefine 3 to mean
>> something else.
>
> I think anything the parser sees is hard-coded, but I could be wrong there.

I did something like define a method that returns #[1 2 3], and then I 
took the result and manipulated it. To my surprise, the method now 
returns the new, manipulated value, instead of what it claims to return. (!)

Apparently you shouldn't do that.

>> Haskell will definitely let you define, say, 2+2=5. You'd be hard
>> pressed to do this "by accident" though...
>
> And what does this result in? Is it just that the expression "2+2"
> matches before "<integer> + <integer>" or some such, so 2+2=5 but 2+3=5
> also?

You can define a new number type, and have it implement arithmetic any 
way you desire. This works because "2" is not an integer. It's a number. 
It's *any* number type.

As insane as that sounds, I have actually /used/ this myself. I 
implemented a type called HalfInteger, which supports numbers rounded to 
the nearest 1/2. So if you say "7", it really stores it as 14. And if 
you say "half", that's really one. And if you do "7 + half", you get 15. 
Ah, but of course, it doesn't /look/ like 15. It looks like 7.5 (via the 
various interfaces that let you inspect it).

The fun part is deciding what the result of half * half should be...

> (I.e., in most fortran implementations, "3" refers to
> an anonymous global variable that holds the value "3".)

Isn't that almost exactly what Smalltalk does with [at least] class names?

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.