     else
       '0'
 
+  @fromNative: (n) ->
+    if n < 0
+      new LongInt -1, digits -n
+    else if n > 0
+      new LongInt 1, digits n
+    else
+      new LongInt 0, null
+
+# ----
+
+# The `number` function provides the public interface.
+
+number = (n = 0) ->
+  switch typeof n
+    when 'number'
+      number.fromNative n
+    when 'string'
+      number.parse n
+
+number.fromNative = (n) ->
+  throw new Error "expected an integer, got #{n}" unless n == Math.floor n
+  asNum n
+
+number.parse = (n) ->
+  unless /^[+-]?\d+$/.test n
+    throw new Error "expected an integer literal, got '#{n}'"
+
+  [s, m] = switch n[0]
+    when '-' then [-1, n[1..]]
+    when '+' then [ 1, n[1..]]
+    else          [ 1, n]
+
+  if m.length <= BASE_LENGTH
+    new CheckedInt parseInt n
+  else
+    parsed = (to) ->
+      if to > 0
+        from = Math.max 0, to - BASE_LENGTH
+        seq.conj parseInt(m[from...to]), -> parsed from
+      else
+        null
+
+    new LongInt s, parsed m.length
+
+
+# ----
+# Exporting.
+
+exports ?= this.pazy ?= {}
+exports.number = number
+
 # ----
 
 # Some quick tests.
 
 if quicktest
-  do ->
-    log "------"
-    a = 98
-    b = 21
-    log "gcd(#{a}, #{b}) = #{new CheckedInt(a).gcd b}"
-
-  do ->
-    log "------"
-    a = new CheckedInt Math.pow 2, 13
-    log "a        = #{a}"
-    log "a * 2    = #{a.times 2}"
-    log "a + 2    = #{a.plus 2}"
-    log "a + 2000 = #{a.plus 2000}"
-
-  do ->
-    log "------"
-    a = -123456789000000
-    log "a = #{a}"
+  blanks = "                                    "
+
+  show = (code) ->
+    s = code.toString().replace /^function\s*\(\)\s*{\s*return\s+(.*);\s*}/, "$1"
+    input = s + blanks[s.length..]
+
+    output =
+      try
+        res = code()
+        type = if res?.constructor? then res.constructor.name else typeof res
+        "#{type} #{res}"
+      catch ex
+        "-- #{ex} --"
+
+    log "#{input} -> #{output}"
+
+
+  a = b = c = 0
+
+  log ''
+  show -> number(98).gcd 21
+
+  log ''
+  show -> a = number Math.pow 2, 13
+  show -> a.plus 2
+  show -> a.times 2
+  show -> a.plus 2000
+
+  log ''
+  show -> number -123456789000000
+  show -> number '-1234'
+  show -> number '-123456789000000'

# Here are the beginnings of the `LongInt` class.

class LongInt
  make_digits = (m) ->
    if m then seq.conj m % BASE, -> make_digits (m / BASE) >> 0 else null

  constructur: (n = 0) ->
    [m, @sign] = if n < 0 then [-n, -1] else [n, 1]
    @digits = make_digits m

  times: (other) ->

  zeroes = BASE.toString()[1..]


class CheckedInt
  getval = (x) -> if x instanceof CheckedInt then x.val else x

  constructor: (@val = 0) ->

  neg: -> new CheckedInt -@val
