Xah Talk Show 2026-02-06 Ep758 JavaScript. Array Sort, Peter Norvig, is Python Acceptable Lisp
Video Summary (Generated by AI, Edited by Human.)
- The video focuses on advanced JavaScript coding, specifically demonstrating how to sort objects within an array using the Array.prototype.sort() method (2:07).
- The speaker, Xah Lee, begins by explaining the "idiocy" of JavaScript's default sort behavior (6:08), which converts elements to strings and compares them by their UTF-16 code units, leading to unexpected results for numbers (7:06).
- He then guides viewers through creating a custom comparison function (known as a "predicate" function (11:46)) to correctly sort an array of objects based on a specific property, like age (30:06).
- Throughout the demonstration, Xah Lee also shares his opinions on:
- The naming conventions for sort functions, preferring "predicate" over "callback" (11:46-13:11).
- Whether JavaScript is a "lisp" (14:04) and delves into a historical anecdote about Peter Norvig calling Python an "acceptable lisp" (18:27).
- The characteristics that truly define a lisp (23:18), such as nested syntax, symbols, macros, and predominantly functional programming (26:59).
- He concludes by showcasing the completed code for sorting objects and reiterates the importance of understanding JavaScript's quirky sort behavior (34:10).
// the idiocy of sort in JavaScript console.log([8, 30, 40].sort()); // [ 30, 40, 8 ]
Peter Norvig on python as acceptable lisp
Characteristics of lisp, you must have
- nested syntax
- symbols
- predominantly functional programing
- lisp macros
- reader macros
some other implicit requirement are:
- Auto memory management (aka garbage collection.)
- Must have builting list or array data type.
Example: Order Objects
// sort objects in array const xarrayOfObjs = [ { "name": "John", "age": 40 }, { "name": "Mary", "age": 19 }, { "name": "Joe", "age": 15 }, { "name": "Dave", "age": 54 }, ]; // the classic way to name sort function is predicate const fSortPredicate = (aa, bb) => { if (aa.age < bb.age) return -1; if (aa.age === bb.age) return 0; if (aa.age > bb.age) return 1; }; // the zoomer idiots, would say fSortCallBackFunction // sort it console.log(xarrayOfObjs.sort(fSortPredicate)); /* [ { name: "Joe", age: 15 }, { name: "Mary", age: 19 }, { name: "John", age: 40 }, { name: "Dave", age: 54 } ] */