[extropy-chat] funky frink function

Alan Eliasen eliasen at mindspring.com
Wed Oct 27 23:52:55 UTC 2004


> Alan Eliasen writes:
> 
>  > You can think of the -> operator as a very-low-precendence divide
>  > operator, if that helps.

Matthew Gingell wrote:
>  How can I do stuff like convert Fahrenheit to Kelvin then? 

    To answer that, I'd need to you to clarify, and so does Frink.  There 
are two totally different measures that you may mean:

    1.) An absolute temperature

    2.) The *size* of a degree Fahrenheit vs. the size of a Kelvin.

    The distinction is subtle, but critical.  Since it's impossible for 
Frink (or me) to guess which one you mean, it makes you disambiguate them. 
Since Fahrenheit and Celsius are silly temperature systems that don't have 
their zero points at absolute zero, they have to be treated specially.

    Let me illustrate the difference through an erroneous news report that a 
friend sent to me:

-----begin quote ----------------
The extended hot spell has seen temperatures cross the 50 degrees
Celsius (122 Fahrenheit) mark. Media reports said the temperature hit
52.1 degrees Celsius (125.8 Fahrenheit) in the northern town of
Kottagudam on Monday.

The temperatures are about five to seven degrees Celsius (41 to 44.6
Fahrenheit) above normal.
------end quote -----------------

    What's wrong with those conversions?

    If you were doing temperature conversions through the web-based 
interface ( http://futureboy.homeip.net/frink/ ,) you'd note that it usually 
gives you helpful hints on how to do them (when it notices certain keywords):

-------------

If you didn't get the answer you expected:

     * Are you doing a temperature calculation? Keep in mind that if you're 
using the Celsius or Fahrenheit system, the zero point is not at absolute 
zero, so these units can't be written as normal multiplicative units. You 
also need to be clear whether you're specifying an absolute temperature or 
the size of a degree in the Fahrenheit or Celsius system. (You use the size 
only when you're indicating the difference between two temperatures.)

    Frink can do it all, but you need to be unambiguous as to which you 
mean, so you don't get a wrong answer. For more information, please see the 
Temperature Scales section of the documentation.

---------------

    And it gives a link to the relevant part of the documentation:

http://futureboy.homeip.net/frinkdocs/index.html#TemperatureScales

    In short,

    1.)  If you mean an absolute temperature, say, converting room 
temperature to the equivalent temperature in Kelvin, you need to use the 
functions c[] or F[] or Celsius[] or Fahrenheit[] to indicate that it's an 
absolute temperature.

    F[72] -> K

    Gives 295.37 K.  You can also write

    F[72] -> C

    or

    C[10] -> F

    (Technical aside:  The C[] and F[] functions work differently if they're 
called with a dimensionless number vs. a unit with dimensions of 
temperature.  The -> operator will also try to call a one-argument-function 
if the right side can't be made to conform.)


    2.)  If you mean the *difference* between two temperatures, such as when 
you're showing the difference between average temperatures, such as in the 
news story above, you'd use "degC" and "degF" or just "K" which indicate the 
*size* of a degree in those scales (a constant factor of 9/5).

    5 degC -> degF

    The last paragraph of the story should have actually read:

    "The temperatures are about five to seven degrees Celsius (9 to 12.6
Fahrenheit) above normal."

    Using the *size* of a degree is necessary when doing thermodynamic 
calculations where the *difference* in temperatures is the critical element.

    The difference is important, so I've decided, rather than guessing what 
the user means, and often guessing wrong, to be a little pedantic, and show 
them how their calculation may be ambiguous, and showing them how to fix it.

    After all, if I help someone to learn something, and think and 
communicate more clearly, I've done my job.  I don't try to read minds, and 
guess drastically wrong sometimes like the Google calculator does.

    Case in point.  Try to guess in advance what the Google Calculator will 
return for each the following:

    1 F + 1 C
    1 K + 1 F
    1 K + 1 F + 1 F
    1 K + 2 F
    1 F + 1 F
    1 F / 1 C
    1 K - 1 C
    1 K / 1 C

    I prefer unambiguity and a wee bit of pedantry over such unpredictable 
behavior.  Better to teach a man to fish, than quietly slip a squid in his 
pants...

>    1 degreeFahrenheit -> "kelvin"
>     5/9 (approx. 0.5555555555555556) kelvin
> 
>  Is there something in Frink like the operator "in" in the Google
>  calculator language, eg:

    The -> operator serves the same purpose.  If you're using the two-line 
interface, it puts the -> between the "from" and "to" for you.

>  (In fairness I think the fault here lies with Herr Fahrenheit, rather
>   than with Mr. Eliasen.)

    Thanks for not laying the blame for such a silly standard on me!  The 
Rankine system has the same size degrees as Fahrenheit, but starts, 
logically, at absolute zero.  That would work too.  Sigh.

>  Also, it's nice that Google accepts "degree Fahrenheit" rather than
>  expecting "degreeFahrenheit." It guess though that the dynamic nature
>  of Frink would make implementing that pretty silly - the lexer would
>  have to know at run time the full symbol table, and defining new
>  identifiers could potentially ambiguate existing ones...

    Precisely.  If someone redefines a local variable called "degree," the 
results are potentially very unexpected and hard to catch.  I'd certainly 
paint myself into an inextensible, unmaintainable, untrustable corner 
cluttered with special cases for everything if I allowed that.

-- 

   Alan Eliasen                 | "Whenever you find you are on the side of
   eliasen at mindspring.com       |  the majority, it is time to pause and
   http://futureboy.homeip.net/ |  reflect."  --Mark Twain



More information about the extropy-chat mailing list