(defcomp ()
  (~docs/page :title "The True Hypermedium Must Define Itself With Itself"
    (p (~tw :tokens "text-stone-500 text-sm italic mb-8")
      "On ontological uniformity, the metacircular web, and why the address of a thing and the thing itself should be made of the same stuff.")

    (~docs/section :title "The test" :id "the-test"
      (p (~tw :tokens "text-stone-600")
        "There is a simple test for whether a medium is truly a medium or merely a carrier. Can it define itself? Can it describe its own semantics, in its own language, and have that description be executable?")
      (p (~tw :tokens "text-stone-600")
        (a :href "https://en.wikipedia.org/wiki/HTML" (~tw :tokens "text-violet-600 hover:underline") "HTML") " cannot express " (a :href "https://en.wikipedia.org/wiki/HTTP" (~tw :tokens "text-violet-600 hover:underline") "HTTP") ". HTTP cannot express " (a :href "https://en.wikipedia.org/wiki/Domain_Name_System" (~tw :tokens "text-violet-600 hover:underline") "DNS") ". " (a :href "https://en.wikipedia.org/wiki/CSS" (~tw :tokens "text-violet-600 hover:underline") "CSS") " cannot describe HTML. " (a :href "https://en.wikipedia.org/wiki/JavaScript" (~tw :tokens "text-violet-600 hover:underline") "JavaScript") " cannot describe CSS in any way that CSS itself would recognise. The web is a stack of mutually opaque layers, each defined in some other notation by some other authority. No layer can see the others. No layer can see itself.")
      (p (~tw :tokens "text-stone-600")
        "This is not a mere inconvenience. It is a structural fact that determines what is and is not possible. A medium that cannot describe itself cannot reason about itself, cannot modify itself, cannot generate itself from itself. It is " (em "inert") " — a carrying wave, not a thinking substance."))

    (~docs/section :title "What Lisp solved" :id "what-lisp-solved"
      (p (~tw :tokens "text-stone-600")
        (a :href "https://en.wikipedia.org/wiki/John_McCarthy_(computer_scientist)" (~tw :tokens "text-violet-600 hover:underline") "McCarthy") " solved this for computation in 1960. The " (a :href "https://en.wikipedia.org/wiki/Lisp_(programming_language)#Connection_to_artificial_intelligence" (~tw :tokens "text-violet-600 hover:underline") "metacircular evaluator") " is an evaluator written in the language it evaluates. " (code "eval") " takes a list and returns a value. The definition of " (code "eval") " is itself a list. So " (code "eval") " can evaluate its own definition. The serpent eats its tail.")
      (p (~tw :tokens "text-stone-600")
        "This is not a party trick. It means the language is " (em "closed under self-description") ". You do not need to step outside Lisp to define Lisp. You do not need a specification document written in English, or a grammar written in " (a :href "https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form" (~tw :tokens "text-violet-600 hover:underline") "BNF") ", or a reference implementation written in " (a :href "https://en.wikipedia.org/wiki/C_(programming_language)" (~tw :tokens "text-violet-600 hover:underline") "C") ". You need only " (a :href "https://en.wikipedia.org/wiki/S-expression" (~tw :tokens "text-violet-600 hover:underline") "s-expressions") " — the same medium the programs are made of.")
      (p (~tw :tokens "text-stone-600")
        "The consequence was immediate and permanent: Lisp became the only language family where the specification, the implementation, the IDE, and the program are all the same kind of thing. Every other language has a boundary between the language and its meta-description. Lisp has none."))

    (~docs/section :title "The web failed the test" :id "web-failed"
      (p (~tw :tokens "text-stone-600")
        "The web has never had this property. Consider:")
      (ul (~tw :tokens "space-y-2 text-stone-600 mt-2")
        (li (strong "URLs") " are opaque strings. They cannot be decomposed, composed, or reasoned about by the content they point to. A URL is a coordinate in an address space, but the address space has no algebra.")
        (li (strong "HTML") " is a tree of tags. It cannot express its own parsing rules, its own rendering semantics, or the meaning of its own elements. The " (code "<html>") " spec is a PDF.")
        (li (strong "CSS") " is a cascade of declarations. It cannot express the box model, the cascade algorithm, or its own selector matching semantics. These are defined in a 400-page prose document.")
        (li (strong "JavaScript") " is a programming language, but it cannot define its own syntax (try writing a " (code "for") " loop as a function), cannot express its own scoping rules, and requires an external parser (written in C++) to bootstrap itself.")
        (li (strong "HTTP") " is a text protocol. It cannot describe its own method semantics, its own caching rules, or its own content negotiation algorithm. These are defined in RFCs."))
      (p (~tw :tokens "text-stone-600")
        "Every layer of the web stack requires stepping outside the medium to define the medium. This is ontological heterogeneity: the thing and the description of the thing are made of different stuff. The map is not the territory, and the map cannot even be " (em "drawn") " in the territory."))

    (~docs/section :title "Ontological uniformity" :id "ontological-uniformity"
      (p (~tw :tokens "text-stone-600")
        "The property we need has a name: " (strong "ontological uniformity") ". Address, verb, query, response, rendering instruction, and specification are all the same kind of thing.")
      (p (~tw :tokens "text-stone-600")
        "In SX, this is literal:")
      (ul (~tw :tokens "space-y-2 text-stone-600 mt-2")
        (li (strong "A URL is an s-expression.") " " (code "/sx/(language.(doc.introduction))") " is not an opaque string — it is a parseable, composable expression. It can be decomposed into parts, transformed by functions, and reasoned about by the same evaluator that renders pages.")
        (li (strong "A response is an s-expression.") " What the server sends is " (code "(div :class \"p-4\" (h2 \"Hello\"))") " — the same notation as the component that produced it. The wire format is the language.")
        (li (strong "A component is an s-expression.") " " (code "(defcomp ~essays/self-defining-medium/card (&key title) (div (h2 title)))") " is simultaneously a definition, a value, and data that can be inspected and transformed.")
        (li (strong "A query is an s-expression.") " The URL " (code "/sx/(language.(spec.core))") " is a function call. The response is the return value. Routing is evaluation.")
        (li (strong "The specification is s-expressions.") " The " (a :href "/sx/(language.(spec.core))" (~tw :tokens "text-violet-600 hover:underline") "SX spec") " is written in SX. The evaluator is defined in the language it evaluates. The parser is defined in the language it parses."))
      (p (~tw :tokens "text-stone-600")
        "There is " (em "one") " kind of stuff. Everything is made of it. The address of a thing and the thing itself are the same kind of thing."))

    (~docs/section :title "What this makes possible" :id "what-this-enables"
      (p (~tw :tokens "text-stone-600")
        "When the medium is uniform, operations that were impossible become trivial:")
      (ul (~tw :tokens "space-y-3 text-stone-600 mt-2")
        (li (strong "URLs compose.") " If " (code "(language (doc introduction))") " and " (code "(language (spec core))") " are both expressions, then " (code "(diff (language (spec signals)) (language (spec eval)))") " is a natural composition. Two queries, side by side. The URL algebra falls out of the expression algebra. You do not need to design it separately — it was always there.")
        (li (strong "The site can show its own source.") " " (code "/sx/(source.(~essays/self-defining-medium/essay-self-defining-medium))") " returns the component definition of this essay. Not a screenshot. Not a prettified view. The actual s-expression that, when evaluated, produces what you are reading now. The page and its source code are the same kind of thing, so displaying one as the other is just evaluation.")
        (li (strong "The spec is executable documentation.") " The " (a :href "/sx/(language.(bootstrapper.self-hosting))" (~tw :tokens "text-violet-600 hover:underline") "self-hosting bootstrapper") " reads the SX spec (written in SX) and produces a working evaluator. The documentation is the implementation. The implementation is the documentation. There is no drift because there is no gap.")
        (li (strong "Inspection is free.") " " (code "/sx/(inspect.(language.(doc.primitives)))") " can show the dependency graph, CSS footprint, and render plan of any page — because the page is data, and data can be walked, analysed, and reported on by the same system that renders it.")
        (li (strong "AI is a native speaker.") " An AI reading SX reads the same notation as the server, the client, the wire, and the spec. There is no translation layer. The AI does not generate code that must be compiled and deployed — it generates expressions that are evaluated. The medium is shared between human, machine, and network.")))

    (~docs/section :title "The metacircular web" :id "metacircular-web"
      (p (~tw :tokens "text-stone-600")
        "McCarthy's " (a :href "https://en.wikipedia.org/wiki/Lisp_(programming_language)#Connection_to_artificial_intelligence" (~tw :tokens "text-violet-600 hover:underline") "metacircular evaluator") " proved that a computing language can define itself. SX extends this proof to a networked hypermedium:")
      (ul (~tw :tokens "space-y-2 text-stone-600 mt-2")
        (li "The " (strong "evaluator") " is defined in SX: " (a :href "/sx/(language.(spec.eval))" (~tw :tokens "text-violet-600 hover:underline") "eval.sx") " specifies the evaluation rules for all expression types, and this specification is itself an SX document.")
        (li "The " (strong "parser") " is defined in SX: " (a :href "/sx/(language.(spec.parser))" (~tw :tokens "text-violet-600 hover:underline") "parser.sx") " specifies tokenization, grammar, and serialization — written in the language it parses.")
        (li "The " (strong "renderer") " is defined in SX: " (a :href "/sx/(language.(spec.render))" (~tw :tokens "text-violet-600 hover:underline") "render.sx") " specifies how s-expressions become HTML, SX wire format, or DOM nodes.")
        (li "The " (strong "router") " is an expression: " (code "/sx/(language.(doc.introduction))") " is a function call that resolves to content. " (a :href "/sx/(language.(spec.router))" (~tw :tokens "text-violet-600 hover:underline") "router.sx") " specifies the matching — in SX.")
        (li "The " (strong "site itself") " is s-expressions: this essay, the navigation tree, the component registry, the wire protocol — all the way down."))
      (p (~tw :tokens "text-stone-600")
        "At every level, the description and the described are the same kind of thing. The specification is not " (em "about") " the system — it " (em "is") " the system. This is not metaphor. It is the literal architecture."))

    (~docs/section :title "Why it matters" :id "why-it-matters"
      (p (~tw :tokens "text-stone-600")
        "A hypermedium that cannot define itself with itself is a hypermedium that depends on something else for its definition. It is parasitic on external authority — standards bodies, specification documents, reference implementations in foreign languages. Every layer of indirection is a layer where the medium's identity is borrowed rather than intrinsic.")
      (p (~tw :tokens "text-stone-600")
        "This dependency has practical consequences. When HTML needs a new element, a committee must convene, a specification must be written (in English, in a PDF), browser vendors must implement it (in C++), and the ecosystem must wait. The medium cannot extend itself. It is extended " (em "by others") ", in " (em "other languages") ", on " (em "other timescales") ".")
      (p (~tw :tokens "text-stone-600")
        "A self-defining medium extends itself by evaluating new definitions. " (code "(defcomp ~essays/self-defining-medium/new-element (&key attrs children) ...)") " — this is not a proposal to a standards body. It is an expression that, when evaluated, adds a new element to the medium. The medium grows by the same mechanism it operates: evaluation of expressions.")
      (p (~tw :tokens "text-stone-600")
        "This is the deepest consequence of ontological uniformity. The medium is not just " (em "described by") " itself — it " (em "grows from") " itself. New components, new routing patterns, new wire formats, new rendering modes — all are expressions evaluated by the evaluator that is itself an expression. The system is " (a :href "https://en.wikipedia.org/wiki/Autopoiesis" (~tw :tokens "text-violet-600 hover:underline") "autopoietic") ": it produces and maintains itself through the same operations it performs."))

    (~docs/section :title "The test, revisited" :id "test-revisited"
      (p (~tw :tokens "text-stone-600")
        "Can the medium define itself with itself?")
      (p (~tw :tokens "text-stone-600")
        "HTML cannot. CSS cannot. JavaScript cannot. HTTP cannot. The web, as a composite medium, cannot — because its layers are mutually opaque and none can express the others.")
      (p (~tw :tokens "text-stone-600")
        "SX can. The evaluator is SX. The parser is SX. The renderer is SX. The wire format is SX. The URLs are SX. The specification is SX. This essay, which argues that the true hypermedium must define itself with itself, is itself an s-expression — evaluated by an evaluator defined in the language it evaluates, served at a URL that is an expression in the language it describes, rendered by a renderer specified in the language it renders.")
      (p (~tw :tokens "text-stone-600")
        "The serpent eats its tail. The medium defines itself with itself. That is the test, and that is the point."))))
