_Based

it.grypho.scala.leonardo.core._Based
See the_Based companion object
case class _Based extends _Value

An integer that remembers the base it is written in.

The fourth sibling of _Number, after _Complex, _Truth and _Rational, and built to the same pattern: a private constructor behind a smart factory, and a value that is read as a number through _Number's widening extractor so no existing case _Number(x) site has to learn about it.

Why the base lives on the value. A base conversion that returns bare digits is only a decomposition: [[15, 15]] is indistinguishable from a matrix typed by hand, and the caller has to remember the base to reassemble it. Putting the base on the value is what makes A := 0xFF still be FF when it is printed an hour later.

The tag is shallow, deliberately. 0xFF + 1 prints 256 in decimal, because Sum.eval reads both operands as numbers and builds a plain _Number. Carrying the base through arithmetic would require deciding whose base wins in 0xFF + 0b1011, and there is no defensible answer — so the base survives display and storage, which is what a base is for, and arithmetic falls back to decimal.

Value parameters

balanced

whether the digits are the balanced set (base 3 only)

base

the radix, 2 .. 36

value

the integer value, held as a Double like every other numeric tier

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait _Value
trait _Expression
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def children: List[_Expression]

A leaf, like every other numeric tier.

A leaf, like every other numeric tier.

Attributes

Definition Classes
def display(precision: Int): String

Renders the digits. precision is accepted for uniformity with the other tiers but is unused: a based integer has no fractional part to round.

Renders the digits. precision is accepted for uniformity with the other tiers but is unused: a based integer has no fractional part to round.

Attributes

override def eval(env: Environment): Either[_Expression, _Value]

Reduces this expression in the given environment.

Reduces this expression in the given environment.

Value parameters

env

variable bindings and display precision

Attributes

Returns

Right(v) when all free variables resolved to concrete values; Left(e) when reduction is partial or impossible

Definition Classes
override def rebuild(c: List[_Expression]): _Expression

Reconstructs the same node shape with replacement sub-expressions.

Reconstructs the same node shape with replacement sub-expressions.

Value parameters

newChildren

replacements in the same order and count as children

Attributes

Definition Classes
override def toString: String

The literal form, which re-parses to this same value — the round-trip invariant.

The literal form, which re-parses to this same value — the round-trip invariant.

Bases 2, 8 and 16 and balanced ternary have prefix literals; any other base has none, so it prints as the tobase(n, b) call that produces it. Both re-parse.

Attributes

Definition Classes
Any

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Inherited fields

lazy val freeVars: Set[String]

Cached set of free variable names; O(1) after the first access.

Cached set of free variable names; O(1) after the first access.

Attributes

Inherited from:
_Expression