bugKawa - Bugs: bug #13865, Symbols don't evaluate to...

 
 

bug #13865: Symbols don't evaluate to themselves when they look like units

Submitted by:  Chris Dean <ctdean>
Submitted on:  Wed 20 Jul 2005 06:09:47 PM UTC  
 
Category: Scheme languageSeverity: 3 - Normal
Item Group: Unexpected resultStatus: Fixed
Privacy: PublicAssigned to: Per Bothner <bothner>
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon 11 Jun 2007 05:22:11 AM UTC, comment #3:

10vols and 7min are now read by the reader as symbols, and resolved to quantities at expansion time, but only if there is no compile-time visible definition for those symbols.

'10vols and '7min always evaluate to symbols.

You can do: (define 7min (* 7 60))

So I think things are cleaner and more consistent now - and also ore compatible with other Schemes.

Per Bothner <bothner>
Project AdministratorIn charge of this item.
Wed 20 Jul 2005 06:41:58 PM UTC, comment #2:

"The bug is when you use a symbol that looks like a unit number but for a unit that doesn't exist."

7min is not a symbol; it's a quantity literal - i.e. a number.
Note that '07min => 7min
If you want a symbol, you meed to escape it:
'|10volts| => 10volts
This just like quoting integers: '|010| => 010

What's happening 7min is resolved at read-time, so it resolves to a self-evaluating quantity. Quoting a self-evaluating quantity has no effect. However, 10volts cannot be resolved at read-time so it reads as an expression that evaluate to the right thing. Quoting that expression will change its meaning.

The inconsistency is arguably a bug: We should probably resolve all quantities at either read-time or at expansion-time. Perhaps the right solution is to allow quantities with unresolved units. The reader returns such a quantity; then the quantity is resolved later, using lexical or dynamic scope to look up units. However, there are problems with this approach.

The "correct" solution may be to change 7min so it behaves like 10volts, in that the unit-resolution is done after read-time.

Per Bothner <bothner>
Project AdministratorIn charge of this item.
Wed 20 Jul 2005 06:16:06 PM UTC, comment #1:

Actually I guess that's not a valid symbol. But it is unexpected that '7min and '10volts evaulate differently.

Chris Dean <ctdean>
Wed 20 Jul 2005 06:09:47 PM UTC, original submission:

Here's a fun Kawa bug.

We all know that units are available in Kawa:

#|kawa:4|# 7min
7min
#|kawa:5|# (+ 8min (* 2 60s))
10.0min

The expression 7min represents seven minutes and units can be used in
arithmatic operations.

What if you use a unit that Kawa doesn't know about? We get a nice
error:

#|kawa:9|# 10volts
10volts
gnu.mapping.UnboundLocationException: Unbound symbol volts$unit
at gnu.expr.ReferenceExp.eval(ReferenceExp.java:115)
at gnu.expr.Expression.apply(Expression.java:35)
...

The bug is when you use a symbol that looks like a unit number but for
a unit that doesn't exist:

#|kawa:11|# '7min ; works
7min
#|kawa:12|# '10volts ; busted
(* 10 volts$unit)

You get this result that is clearly not a symbol.

Chris Dean <ctdean>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by bothner (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 11 Jun 2007 05:22:11 AM UTCbothnerStatusNone=>Fixed
      Open/ClosedOpen=>Closed
    Wed 20 Jul 2005 06:41:58 PM UTCbothnerAssigned toNone=>bothner

    Back to the top


    Powered by Savane 3.1-cleanup1