Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions book/src/examples/example-numbat_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ icon: lucide/file-code

# 1. Imports

use prelude # This is not necessary. The 'prelude'
use prelude::* # This is not necessary. The 'prelude'
# module will always be loaded upon startup

use units::stoney # Load a specific module
use units::stoney::* # Load a specific module

# 2. Numbers

Expand Down
2 changes: 1 addition & 1 deletion examples/geographical_distance.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# - http://www.movable-type.co.uk/scripts/latlong-vincenty.html
# - https://en.wikipedia.org/wiki/Vincenty%27s_formulae

use numerics::fixed_point
use numerics::fixed_point::*

struct LatLon {
name: String,
Expand Down
4 changes: 2 additions & 2 deletions examples/numbat_syntax.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

# 1. Imports

use prelude # This is not necessary. The 'prelude'
use prelude::* # This is not necessary. The 'prelude'
# module will always be loaded upon startup

use units::stoney # Load a specific module
use units::stoney::* # Load a specific module

# 2. Numbers

Expand Down
2 changes: 1 addition & 1 deletion examples/tests/color.nbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use extra::color
use extra::color::*

assert_eq(0x000000 -> color, black)
assert_eq(0xffffff -> color, white)
Expand Down
6 changes: 3 additions & 3 deletions examples/tests/numerics.nbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use numerics::solve
use numerics::diff
use numerics::fixed_point
use numerics::solve::*
use numerics::diff::*
use numerics::fixed_point::*

# Root finding

Expand Down
2 changes: 1 addition & 1 deletion examples/tests/vector3.nbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use extra::vector3
use extra::vector3::*

# Basic angular momentum computation
let r = vec(3 m, 4 m, 0 m)
Expand Down
2 changes: 1 addition & 1 deletion examples/what_if_11.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# https://what-if.xkcd.com/11/

use extra::astronomy
use extra::astronomy::*

@aliases(birds)
unit bird
Expand Down
2 changes: 1 addition & 1 deletion examples/xkcd_681.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# https://xkcd.com/681/

use extra::astronomy
use extra::astronomy::*

fn well_depth(mass: Mass, radius: Length) -> Length =
G × mass / (g0 × radius) -> km
Expand Down
2 changes: 1 addition & 1 deletion numbat-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Cli {

if self.config.load_prelude {
let result = self.parse_and_evaluate(
"use prelude",
"use prelude::*",
CodeSource::Internal,
ExecutionMode::Normal,
PrettyPrintMode::Never,
Expand Down
2 changes: 1 addition & 1 deletion numbat-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Numbat {
pub fn new(load_prelude: bool, enable_pretty_printing: bool, format_type: FormatType) -> Self {
let mut ctx = Context::new(BuiltinModuleImporter::default());
if load_prelude {
let _ = ctx.interpret("use prelude", CodeSource::Internal).unwrap();
let _ = ctx.interpret("use prelude::*", CodeSource::Internal).unwrap();
}
ctx.set_terminal_width(Some(84)); // terminal width with current layout
Numbat {
Expand Down
2 changes: 1 addition & 1 deletion numbat/benches/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn import_prelude(c: &mut Criterion) {
c.bench_function("Import prelude", |b| {
b.iter_with_setup(
|| context.clone(),
|mut ctx| ctx.interpret("use prelude", CodeSource::Text),
|mut ctx| ctx.interpret("use prelude::*", CodeSource::Text),
)
});
}
Expand Down
4 changes: 2 additions & 2 deletions numbat/examples/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ fn prepare_context() -> Context {

fn main() {
let mut ctx = prepare_context();
let _result = ctx.interpret("use all", CodeSource::Internal).unwrap();
let _result = ctx.interpret("use all::*", CodeSource::Internal).unwrap();

let mut example_ctx = prepare_context();
let _result = example_ctx
.interpret("use prelude", CodeSource::Internal)
.interpret("use prelude::*", CodeSource::Internal)
.unwrap();

let mut args = std::env::args();
Expand Down
22 changes: 11 additions & 11 deletions numbat/modules/all.nbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use prelude
use prelude::*

use units::currencies
use units::stoney
use units::hartree
use units::currencies::*
use units::stoney::*
use units::hartree::*

use extra::algebra
use extra::color
use extra::astronomy
use extra::cooking
use extra::algebra::*
use extra::color::*
use extra::astronomy::*
use extra::cooking::*

use numerics::diff
use numerics::solve
use numerics::fixed_point
use numerics::diff::*
use numerics::solve::*
use numerics::fixed_point::*
12 changes: 6 additions & 6 deletions numbat/modules/chemistry/elements.nbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use units::si
use units::si::*

struct _ChemicalElementRaw {
pub struct _ChemicalElementRaw {
symbol: String,
name: String,
atomic_number: Scalar,
Expand All @@ -15,9 +15,9 @@ struct _ChemicalElementRaw {
vaporization_heat_kilojoule_per_mole: Scalar,
}

fn _get_chemical_element_data_raw(pattern: String) -> _ChemicalElementRaw
pub fn _get_chemical_element_data_raw(pattern: String) -> _ChemicalElementRaw

struct ChemicalElement {
pub struct ChemicalElement {
symbol: String,
name: String,
atomic_number: Scalar,
Expand All @@ -32,7 +32,7 @@ struct ChemicalElement {
vaporization_heat: MolarEnthalpyOfVaporization,
}

fn _convert_from_raw(raw: _ChemicalElementRaw) -> ChemicalElement =
pub fn _convert_from_raw(raw: _ChemicalElementRaw) -> ChemicalElement =
ChemicalElement {
symbol: raw.symbol,
name: raw.name,
Expand All @@ -52,5 +52,5 @@ fn _convert_from_raw(raw: _ChemicalElementRaw) -> ChemicalElement =
@description("Get properties of a chemical element by its symbol or name (case-insensitive).")
@example("element(\"H\")", "Get the entire element struct for hydrogen.")
@example("element(\"hydrogen\").ionization_energy", "Get the ionization energy of hydrogen.")
fn element(pattern: String) -> ChemicalElement =
pub fn element(pattern: String) -> ChemicalElement =
_convert_from_raw(_get_chemical_element_data_raw(pattern))
4 changes: 2 additions & 2 deletions numbat/modules/core/debug.nbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::scalar
use core::scalar::*

@description("Print the value (and type) of the argument and return it. Useful for debugging.")
@example("inspect(36 km / 1.5 hours) * 1 day")
@example("range(1, 3) |> map(sqr) |> map(inspect) |> sum")
fn inspect<T>(x: T) -> T
pub fn inspect<T>(x: T) -> T
148 changes: 74 additions & 74 deletions numbat/modules/core/dimensions.nbt
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
### Physical dimensions

dimension Angle = 1 # SI: plane angle
dimension SolidAngle = Angle^2
pub dimension Angle = 1 # SI: plane angle
pub dimension SolidAngle = Angle^2

dimension Length
dimension Area = Length^2
dimension Volume = Length^3
dimension Wavenumber = 1 / Length
pub dimension Length
pub dimension Area = Length^2
pub dimension Volume = Length^3
pub dimension Wavenumber = 1 / Length

dimension Time
dimension Frequency = 1 / Time
dimension Velocity = Length / Time
dimension Acceleration = Length / Time^2
dimension Jerk = Length / Time^3
dimension FlowRate = Volume / Time
pub dimension Time
pub dimension Frequency = 1 / Time
pub dimension Velocity = Length / Time
pub dimension Acceleration = Length / Time^2
pub dimension Jerk = Length / Time^3
pub dimension FlowRate = Volume / Time

dimension Mass
dimension Momentum = Mass × Velocity
dimension Force = Mass × Acceleration = Momentum / Time
dimension Energy = Momentum^2 / Mass = Mass × Velocity^2 = Force × Length # also: work, amount of heat
dimension Power = Energy / Time = Force × Velocity
dimension Pressure = Force / Area = Energy / Volume # also: stress
dimension Action = Energy × Time
dimension MassDensity = Mass / Length^3
dimension MomentOfInertia = Mass × Length^2 / Angle^2
dimension AngularMomentum = MomentOfInertia × Angle / Time = Mass × Length^2 / Time / Angle
dimension Torque = Length × Force / Angle # also: moment of force
dimension EnergyDensity = Energy / Volume
dimension MassFlow = Mass / Time
pub dimension Mass
pub dimension Momentum = Mass × Velocity
pub dimension Force = Mass × Acceleration = Momentum / Time
pub dimension Energy = Momentum^2 / Mass = Mass × Velocity^2 = Force × Length # also: work, amount of heat
pub dimension Power = Energy / Time = Force × Velocity
pub dimension Pressure = Force / Area = Energy / Volume # also: stress
pub dimension Action = Energy × Time
pub dimension MassDensity = Mass / Length^3
pub dimension MomentOfInertia = Mass × Length^2 / Angle^2
pub dimension AngularMomentum = MomentOfInertia × Angle / Time = Mass × Length^2 / Time / Angle
pub dimension Torque = Length × Force / Angle # also: moment of force
pub dimension EnergyDensity = Energy / Volume
pub dimension MassFlow = Mass / Time

dimension Current
dimension ElectricCharge = Current × Time
dimension Voltage = Energy / ElectricCharge = Power / Current # ISQ: electric tension, SI: electric potential difference
dimension Capacitance = ElectricCharge / Voltage
dimension ElectricResistance = Voltage / Current
dimension Resistivity = ElectricResistance × Length
dimension ElectricConductance = 1 / ElectricResistance
dimension Conductivity = ElectricConductance / Length
dimension MagneticFluxDensity = Force / (ElectricCharge × Velocity)
dimension MagneticFlux = MagneticFluxDensity × Area = Voltage × Time
dimension MagneticFieldStrength = Current / Length
dimension Inductance = MagneticFlux / Current
dimension ElectricChargeDensity = ElectricCharge / Volume
dimension CurrentDensity = Current / Area
dimension ElectricDipoleMoment = ElectricCharge × Length
dimension ElectricQuadrupoleMoment = ElectricCharge × Length^2
dimension MagneticDipoleMoment = Current × Area = Torque / MagneticFluxDensity
dimension ElectricFieldStrength = Voltage / Length
dimension ElectricDisplacementFieldStrength = ElectricCharge / Area
dimension ElectricPermittivity = Time^4 × Current^2 / Mass / Length^3 × Angle = ElectricDisplacementFieldStrength / ElectricFieldStrength × Angle
dimension MagneticPermeability = Length × Mass / Time^2 / Current^2 / Angle = MagneticFluxDensity / MagneticFieldStrength / Angle
dimension Polarizability = ElectricDipoleMoment / ElectricFieldStrength = Current^2 × Time^4 / Mass
dimension ElectricMobility = Velocity / ElectricFieldStrength
pub dimension Current
pub dimension ElectricCharge = Current × Time
pub dimension Voltage = Energy / ElectricCharge = Power / Current # ISQ: electric tension, SI: electric potential difference
pub dimension Capacitance = ElectricCharge / Voltage
pub dimension ElectricResistance = Voltage / Current
pub dimension Resistivity = ElectricResistance × Length
pub dimension ElectricConductance = 1 / ElectricResistance
pub dimension Conductivity = ElectricConductance / Length
pub dimension MagneticFluxDensity = Force / (ElectricCharge × Velocity)
pub dimension MagneticFlux = MagneticFluxDensity × Area = Voltage × Time
pub dimension MagneticFieldStrength = Current / Length
pub dimension Inductance = MagneticFlux / Current
pub dimension ElectricChargeDensity = ElectricCharge / Volume
pub dimension CurrentDensity = Current / Area
pub dimension ElectricDipoleMoment = ElectricCharge × Length
pub dimension ElectricQuadrupoleMoment = ElectricCharge × Length^2
pub dimension MagneticDipoleMoment = Current × Area = Torque / MagneticFluxDensity
pub dimension ElectricFieldStrength = Voltage / Length
pub dimension ElectricDisplacementFieldStrength = ElectricCharge / Area
pub dimension ElectricPermittivity = Time^4 × Current^2 / Mass / Length^3 × Angle = ElectricDisplacementFieldStrength / ElectricFieldStrength × Angle
pub dimension MagneticPermeability = Length × Mass / Time^2 / Current^2 / Angle = MagneticFluxDensity / MagneticFieldStrength / Angle
pub dimension Polarizability = ElectricDipoleMoment / ElectricFieldStrength = Current^2 × Time^4 / Mass
pub dimension ElectricMobility = Velocity / ElectricFieldStrength

dimension Temperature
dimension Entropy = Energy / Temperature
dimension HeatCapacity = Energy / Temperature
dimension SpecificHeatCapacity = HeatCapacity / Mass
dimension ThermalConductivity = Power / (Length × Temperature)
dimension ThermalTransmittance = Power / (Length^2 × Temperature)
pub dimension Temperature
pub dimension Entropy = Energy / Temperature
pub dimension HeatCapacity = Energy / Temperature
pub dimension SpecificHeatCapacity = HeatCapacity / Mass
pub dimension ThermalConductivity = Power / (Length × Temperature)
pub dimension ThermalTransmittance = Power / (Length^2 × Temperature)

dimension AmountOfSubstance
dimension MolarMass = Mass / AmountOfSubstance
dimension MolarVolume = Volume / AmountOfSubstance
dimension CatalyticActivity = AmountOfSubstance / Time
dimension Molarity = AmountOfSubstance / Volume
dimension Molality = AmountOfSubstance / Mass
dimension ChemicalPotential = Energy / AmountOfSubstance
dimension MolarEnthalpyOfVaporization = Energy / AmountOfSubstance
dimension MolarHeatCapacity = HeatCapacity / AmountOfSubstance
pub dimension AmountOfSubstance
pub dimension MolarMass = Mass / AmountOfSubstance
pub dimension MolarVolume = Volume / AmountOfSubstance
pub dimension CatalyticActivity = AmountOfSubstance / Time
pub dimension Molarity = AmountOfSubstance / Volume
pub dimension Molality = AmountOfSubstance / Mass
pub dimension ChemicalPotential = Energy / AmountOfSubstance
pub dimension MolarEnthalpyOfVaporization = Energy / AmountOfSubstance
pub dimension MolarHeatCapacity = HeatCapacity / AmountOfSubstance

dimension LuminousIntensity
dimension LuminousFlux = LuminousIntensity × Angle^2
dimension Illuminance = LuminousFlux / Area
dimension Luminance = LuminousIntensity / Area
dimension Irradiance = Power / Area
pub dimension LuminousIntensity
pub dimension LuminousFlux = LuminousIntensity × Angle^2
pub dimension Illuminance = LuminousFlux / Area
pub dimension Luminance = LuminousIntensity / Area
pub dimension Irradiance = Power / Area

dimension Activity = 1 / Time
dimension AbsorbedDose = Energy / Mass
dimension EquivalentDose = Energy / Mass # also: dose equivalent
dimension SpecificActivity = Activity / Mass
pub dimension Activity = 1 / Time
pub dimension AbsorbedDose = Energy / Mass
pub dimension EquivalentDose = Energy / Mass # also: dose equivalent
pub dimension SpecificActivity = Activity / Mass

dimension DynamicViscosity = Pressure × Time
dimension KinematicViscosity = Length^2 / Time
pub dimension DynamicViscosity = Pressure × Time
pub dimension KinematicViscosity = Length^2 / Time
4 changes: 2 additions & 2 deletions numbat/modules/core/error.nbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::scalar
use core::scalar::*

@description("Throw an error with the specified message. Stops the execution of the program.")
fn error<T>(message: String) -> T
pub fn error<T>(message: String) -> T
Loading
Loading