← Back to context

Comment by lispm

17 days ago

> Lisp can't at the same time be uniquely powerful, but also no different to any other language

There are lots of programming languages which are "uniquely powerful": C++, Prolog, Haskell, ...

> Lisp is a uniquely flexible language

I'm not sure if I buy "uniquely", but "very" would be fine.

> Uniquely flexible languages impose a cost for readability and collaboration.

At the same time it provides also important features for readability and collaboration. There are code bases of complex Lisp software, which are maintained by small&changing teams for several decades.

Lisp is effective not so much for "lone wolfs", but for small teams (5 to 100 people) working in a shared infrastructure with larger groups. Example: SBCL is a complex Common Lisp implementation, which goes back to the early 80s (-> Spice Lisp). SBCL is maintained by a group of people and has monthly releases. Around it there is an eco-system of software.

Simpler Lisp dialects can also be effective for larger groups. For example there are many people using "AutoLisp" (or versions of it), a simple Lisp dialect for scripting AutoCAD (and various competitors).

Fair thoughts, all. I'm a big fan of Haskell, but I'm not without sympathy to Lisp, even if my own experience of the latter has been somewhat bumpy.

I'm curious, what are some of the important features for readability and collaboration that you mention Lisp offers?

  • Assuming Common Lisp. Many features found their way into other languages (or were provided there early, too -> for example named arguments in Smalltalk). Thus some may not look novel, but a practically used since several decades and are well integrated into the language, tools and designed for interactive usage: development, coding, extending and also reading code can be done in parallel while using the software.

    It's actually very different to 'read source code and use batch compilation', from 'interactively exploring the source code and the running program at the same time'.

    Relatively typical is the preference for long and descriptive names in larger software bases, with lots of documentation strings and named arguments.

    * Development environments come with many introspection capabilities: describe, documentation, inspect, break, ...

    * There are standard features for built in documentation strings for functions, variables, macros, classes, ...

    * Macros allow very descriptive code. One can extended the language such that the constructs are very descriptive and declarative.

    * Macros allow embedded domain specific code, which makes the code very readable, and gets rid of unnecessary programming details.

    * Symbols can get arbitrary long and can contain arbitrary identifiers.

    * Functions often have named parameters. Source code typical makes extensive use of named parameters.

    * Details like manual memory management are not needed. -> code is simplified

    * Many language constructs have an explicit and tight scope. -> for examples variables can't be introduced in arbitrary places in a scope.

    * The language standard is very stable.

    * Language extension is built-in (macros, reader, meta-object protocol, ...) and everyone uses the same mechanisms, with full language support in the extensions. -> no need tof additional and external macro processors, templating engine, XML engines, ...

    * Users can more easily share/improve/collect deep language extensions, without the need to hack specific compiler implementation details, since the extension language is Lisp itself.

    * Typical code is not using short identifiers or one letter identifiers with a complex operator hierarchy.

    * Development is typically interactive, where one loads a program into Lisp and then one can query the Lisp system about the software (edit, who-calls, graph classes, show documentation, ...). Thus the developer does not work only with text, but can live interact and inspect the software, which is always in a debug mode.

    * The code can contain examples and tests, which can be immediately tried out by a programmer while reading the code.

    * There is a standardized language with widely different implementations. For collaboration it is can be very helpful that even then much of the core code can be shared, instead of having to reinvent the wheel for those different environments. The Lisp code can query the runtime and adapt itself to the implementation. Other systems have that too with an extra external configuration tools. Often it is possible for a different user that shipped source changes can be loaded into a running software. It is then immediately active and information about argument lists, documentation, class hierarchies, etc. is instantly updated.

    Here is an example for a interactive definition of a function with documentation, type declarations and named arguments.

        CL-USER 12 > (defun some-example-for-hackernews (&key author to title text)
    
                      (declare (type symbol author to)
                               (type list text))
    
                      "This code is an example for Hackernews, to show off readability features."
    
                      (print (list author 'writes 'to to))
                      (print (list 'title 'is title))
                      (print text)
    
                      (values))
        SOME-EXAMPLE-FOR-HACKERNEWS
    
        CL-USER 13 > (some-example-for-hackernews
                      :author 'lispm
                      :to 'troad
                      :title 'lisp-features
                      :text '("example for a function with documentation, type declaration and named arguments"))
    
        (LISPM WRITES TO TROAD) 
        (TITLE IS LISP-FEATURES) 
        ("example for a function with documentation, type declaration and named arguments") 
    
        CL-USER 14 > (documentation 'some-example-for-hackernews 'function)
        "This code is an example for Hackernews, to show off readability features."
    

    Another example: DEFCLASS is a macro for defining classes. Again, documentation and introspection is built-in. The developer does not need to read and work with dead text, but can interactively explore and try out the software, while using self-documentation features. As one can see the macro uses similar named argument lists as functions. There is a slot named WARP-CLASS and arguments for types, initialization arguments, documentation, and so on. The macro then expand this form to larger code and saves the user a lot of typing. The language can use similar mechanisms to be extend with other features, without the need to go into compiler hacking. Thus language extensions can be written and documented by users in a standard way, which greatly enhances the way how to use and understand language extensions.

        CL-USER 31 > (defclass space-ship ()
    
                       ((name :type 'string :initarg :name :documentation "The space ship name")
                        (warp-class :type 'number :initarg :warp-class :documentation "The warp class describes the generation of the warp propulsion system. 1 is the slowest and 5 is the fastest")
                        (warp-speed :type 'number :initform 0 :documentation "The current warp speed"))
    
                       (:documentation "this class describes space ships with warp propulsion"))
        #<STANDARD-CLASS SPACE-SHIP 8220381C2B>
    
        CL-USER 32 > (make-instance 'space-ship
                                    :name "Gondor"
                                    :warp-class 3)
        #<SPACE-SHIP 8010170AE3>
    
        CL-USER 33 > (describe *)
    
        #<SPACE-SHIP 8010170AE3> is a SPACE-SHIP
        NAME            "Gondor"
        WARP-CLASS      3
        WARP-SPEED      0
    
        CL-USER 34 > (documentation 'space-ship 'type)
        "this class describes space ships with warp propulsion"

    • Many thanks for taking the time to show those features off, it's very kind of you and I genuinely appreciate it. I spent about two hours playing with SBCL and its documentation / inspection features, inspired by the examples you gave, and another hour reading some docs. Very neat! Aside from reading a book on CL some time back, my most significant (but still quite peripheral) experience with Lisps has been Clojure, and while I feel like Clojure has better onboarding, I must say that CL feels much more pleasant to actually work with. (If I never see another Java stack trace, it will be too soon.)

      I do very much like the named and typed arguments. I took the liberty to do some further reading about SBCL's capacity for compile-time type checks [0], which is a pleasant surprise. I did some quick experimenting, and was also quite impressed with SBCL for catching function calls passing unknown keys at compile time, before the call is invoked.

      Perhaps the fact that many Lisp guides feel compelled to start with a terse implementation of lambda calculus might actually be somewhat of a disservice, in hiding the more practical side of the language?

      [0] https://lispcookbook.github.io/cl-cookbook/type.html

      2 replies →