Tobias C. Rittweiler schrieb:
> Hi!
> 
> Has anyone added special syntax to allow writing numeric literals with
> physical units? So you can write 12m + 34cm, and would get 12.34m.
> 
> My question is how would you modify the BNF the most sensible way to
> allow for this? The above example is simple, but think of 42 km/h.

You don't need special syntax in order to work with units. You just need
to normalize all input to SI units like meter, second and meter per second:

km=1000.
m=1.
dm=0.1
cm=0.01
mm=0.001

s= 1.
h = 3600.

m_s=m/s
km_h=km/h

length_in_mm = (12*m + 34*cm)/mm
speed = 5*km_h


For what purpose do you want to have physical units in Python syntax? Do
you need to verify your formulas?

Christian

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to