manual:chapter3:units

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
manual:chapter3:units [2018/10/25 09:34]
claudio
manual:chapter3:units [2018/10/25 10:09]
claudio
Line 28: Line 28:
  
 Results of an addition or subtraction between consistent units will produce a result with the units of the first argument (argument in level 2 of the stack at the time of the operation, or the left argument in an algebraic expression). Results of an addition or subtraction between consistent units will produce a result with the units of the first argument (argument in level 2 of the stack at the time of the operation, or the left argument in an algebraic expression).
 +
 +==== Custom Units ====
 +
 +Units in newRPL can be arbitrary symbols, not just the ones predefined in the system. For example, adding ''3_apples'' and ''2_apples'' will produce ''5_apples'' as expected. In this case, ''apples'' is a custom unit without a definition. Units without a definition are considered base units. The system already includes base units for mass, length, time, etc. but any number of new base units can be added simply by using new symbols.
 +
 +Custom units can also be defined as derived units, in terms of other base units. This is done with the ''UDEFINE'' command. For example typing ''750_ml'' ''%%'bigmug'%%'' ''UDEFINE'' would define a unit named ''bigmug'' as 750 ml. From that moment ''bigmug'' can be used in the exact same way as any system-defined unit, and it will be considered consistent with all other volume units.
 +
 +New units can also be defined in terms of new (unknown) base units. For example typing ''3_apples'' ''%%'oranges'%%'' ''UDEFINE'' will define ''oranges'' as equivalent to 3 ''apples'', where ''apples'' is a base unit (amount of fruit?).
 +From that moment the addition ''2_[oranges]+3_[apples]'' will result in ''3_oranges'' since the units of the result will match the units of the left operand, and the 3 apples were automatically converted to 1 orange.
 +
 +Custom units work systemwide, the command ''ULIST'' returns a list of all the custom units that are defined in the system. To remove a unit definition use the ''UPURGE'' command. Following the previous example, typing ''%%'oranges'%%'' ''UPURGE'' will undefine the unit. Notice that the unit ''oranges'' definition was removed, which means this symbol now represents an unknown base unit, then ''2_[oranges]+3_[apples]'' cannot proceed since oranges and apples are now considered as unrelated base units.
 +
 +
 +==== Available Units ====
  
 This is a list of the units available in the ''Units'' menu on newRPL: This is a list of the units available in the ''Units'' menu on newRPL:
  • manual/chapter3/units.txt
  • Last modified: 2019/11/19 13:34
  • by claudio