Hacker News new | ask | show | jobs
by jangid 1854 days ago
What I like about Lisp's syntax is that the cursor (point) is always in a complete Lisp program. You move up one set of parenthesis, again a complete program. Move up further .... till you reach the top (file-level).

So this gives good opportunity to Editor makers. Compile "this" level, 1-level-up, 2-level-up and so on. In an editor you can always check your program while coding.

Example is Cider package for Emacs for Clojure programming language.

2 comments

This isn't necessarily true, as various special forms have keywords with special meaning themselves that are enclosed in parentheses.

This is a complete Scheme program:

  (cond
    [(= 1 0) (error "should be unreachabe")]
    (else    "should always be reached"))
However this:

    (else    "should always be reached")
Is not a Scheme program, unless the binding `else` be defined in the current scope..
It is for this reason that it is misleading to say that lisp languages "have no syntax" - they do have considerable constraints on their structure. It's almost as if there's a third layer between "syntax" and "semantics" - or perhaps the word "syntax" conceals two distinct types of structure.
'syntax' is actually a useful term in this context. But this syntax works on token tree data. The token trees is the code as s-expression data.

The Lisp syntax then is defined for these token trees.

For example the syntax for an argument list in Common Lisp is defined with an EBNF syntax description form:

  lambda-list::= (var* 
                  [&optional {var | (var [init-form [supplied-p-parameter]])}*] 
                  [&rest var] 
                  [&key {var | ({var | (keyword-name var)} [init-form [supplied-p-parameter]])}* [&allow-other-keys]] 
                  [&aux {var | (var [init-form])}*])
The XML people came up with the word "schema" for the remaining shape of a datum when the details of recovering the tree itself from the tokens are settled.
Is the second one less of a program than (frobnicate "foo")? Looks about the same to me: a program that crashes unless we (define frobnicate …) first.
Crashes? in most cases simply does not compile because Scheme has static scope; it is thus not a program.

But, we can of course go even further than that:

   (library (main constants (0 0 1))
     (export pi)
     (define pi 3.1415926535)
   )
`(0 0 1)` is not a valid Scheme program, no matter what one define at any point; an integer can never be the operand of an expression.
Understanding what lisp-ers mean by 'repl-driven development' -- and why a python or node repl isn't it -- is really hard for people who don't get this, and haven't used it in practice.
(I use mostly Clojure)

It's not even only about the syntax. The Python environment, as far as I understand (and please correct me if I'm wrong), does not support re-definitions very well. Some things can be re-defined, but some cannot. So that's a problem in itself which makes REPL-driven development not very useful in Python.

Not sure why you'd say that. I redefine things often in Python.
What about classes? Can you re-define those?
Not only can you redefine classes, you can change the class an object belongs to. Just point `obj.__class__` at something else, or change `cls.__bases__` to reorganize the class's inheritance hierarchy.
Yes, easily. Just re-execute the class definition code.