Context Dependent Syntax, Python, Lisp setf

By Xah Lee. Date: . Last updated: .

Python Ruby JavaScript Etc

Many language have the syntax a[i] = x to assign or replace a element in a list. It is a syntax that has context dependent semantics.

The issue here, is that it uses the same notation to indicate a “place”. For example, a[3] is the third index in array. So,

a[3]=4 means make the third index to have value of 4.

The problem here, is that there's different meaning of a[3] in the 2 cases. Normally, a[3] evaluates to a value. But in a[3]=4, the a[3] does not evaluate. Rather, it's part of the syntax that tells the compiler of a “storage location”.

So, you see, the a[3] in print a[3] and a[3]=4 have diff meaning, and is context dependent.

Common Lisp setf

The Common Lisp setf is the most screwed design in computer languages possible.

here's elisp manual explaining setf.

elisp manual generalized variable 2017 04 07
(info "(elisp) Generalized Variables")

Forth and Bliss

And of course Forth also explicitly has fetch and store ops so you can say 3 a @ . and x @ 3 a ! for printing and assignment

The Bliss language (DEC Systems lang) had a unary dot operator to return a value so you'd say a[3]=.x and print .a[3]

—from Bahstin Beer Bum @mmaug, 2016-10-05

Context Dependent Syntax

  1. JavaScript Syntax Soup: p in o
  2. Python Syntax Soup: x in y
  3. Context Dependent Syntax, Python, Lisp setf

If you have a question, put $5 at patreon and message me.