/r/lisp

Photograph via snooOG

A subreddit for the Lisp family of programming languages.

Lisp family of programming languages

Lisp subreddits:

Language References

  • Common Lisp

  • Scheme

  • Racket

  • Clojure

  • Tools

    Tutorials/FAQs

    Resources:

    Search

    Books

    • Free, On-line
  • Other Books

  • Food for Thought

    Implementations

    • CL Open Source
  • CL Commercial
  • CL Developmental
  • CL Historical
  • Scheme
  • Mature Dialects
  • Developing Dialects
  • Exo-Lisps
  • /r/lisp

    39,730 Subscribers

    1

    1973 Lisp code presented to Zagreb Tendencies 5 exhibition

    At the time, it was one of the large exhibition for computer art. I've read that this piece was influencial.

    This is very likely in early INTERLISP or maybe VLISP (Vincennes lisp). I've tried to run it with Medley but didn't find how to paste the text.

    Can anyone here run it and screenshot the result?

    ;; PATRICK GREUSSAY
    ;; VINCENNES
    ;; S-EXPRESSIONS
    ;; 10-4-73
    
    ;; CET ARTICLE EST UN PROGRAMME, C'EST AUSSI UNE DESCRIPTIONm
    ;; C'EST EGALEMENT UN ENSEMBLE D'ALGORITHMES,
    ;; C'EST AUSSI D'UNE CERTAINE FACON UN OU DES MODELES
    
    ;; LE PROGRAMME, OU SA REPRESENTATION VISUELLE EST UN
    ;; OBSERVABLE; L'OBSERVE ETAIT UNE MINUSCULE PIECE POUR PIANO,
    ;; L'OBSERVABLE EST UN ENSEMBLE DE FORMULATIONS LINGUISTIQUES.
    
    ;; S'IL S'AGIT D'UN OU DE PLUSIEURS ALGORHITMES, ILS NE
    ;; PRODUISENT PAS A PROPREMENT PARLER DE RESULTATS. ILS SONT.
    ;; EN MACHINE. DANS UNE MACHINE IMAGINAIRE. COMME LE MODELE.
    
    ;; EN FAIT, UN ORDINATEUR N'EST RIEN D'AUTRE QU'UN DISPO-
    ;; SITIF A ENONCER DISONS A REVER DES THEORIES
    
    DEFINE ((
        (CDDAR
        (LAMBDA (L)
         (CAR (CDAR L))))
    
    (CADAR (LAMBDA (L)
    (CAR (CDAR L))))
    
    (MATCH
        (LAMBDA (REF PAT)
            (PROG (L PR PP P1 X)
                ; initialisation;
                (SETQ PAT ( CONS ( CONS NIL
                    (CONS REF REF)) PAT))
                (MAP (CDR PAT)
                    (QUOTE (LAMBDA (L)
                        (AND 
                            (NOT (ATOM (CAR L)))
                            (RPLACD (CAR L) (CONS))))))
                (SETQ L PAT)
                (SETQ PR REF)
    
                ; boucle;
                (SETQ PP (CDR L))
                (AND
                    (NULL PR)
                    (RETURN))
                (AND
                    (ATOM (SETQ X (CAR PP)))
                    (GO F1))
                (RPLACA (CDAR PP) PR)
                (RPLACD (CDAR PP) PR)
                (GO REF)
    F1          (AND
                    (EQ X (CAR PR))
                    (GO F2))
                (SETQ PR (CDR CDDAR L)))
                (RPLACD (CDAR L) PR)
                (GO L)
    F2          (SETQ PR (CDR PR))
    REF         (SETQ P1 PP)            
                (AND 
                    (SETQ PP (CDR PP))
                    (GO F))
                    ; -2-;
                    ; matching reussi;
                (AND
                    PR
                    (EQ L P1)
                    (RPLACD (CDAR L)(QUOTE QUOTE)))
                (RPLACA (QUOTE LISTE-RESULTAT))
    
                ; affectation des variables;
                (MAP (CDR PAT)
                    (QUOTE (LAMBDA (L)
                        (AND
                            (NOT (ATOM (CAR L)))
                            (RPLACA (QUOTE LISTE-RESULTAT)
                                (CONS (CONS (CAAR L)
                                (PROG (REF)
                                    (SETQ PR (CADAR L))
                                    
                                    ; pointeur gauche DS PR ;
                                    (AND
                                        (EQ (CDDAR L) (QUOTE QUOTE))
                                        (RPLACD (CDAR L)))
                                    (SETQ P1 (CDDAR L))
                                    
                                    ; pointeur droit DS P1;
                                L   (AND
                                        (EQ PR P1)
                                        (RETURN REF))
                                    (SETQ REF (NCONC REF
                                        (LIST (CAR PR))))
                                    (SETQ PR (CDR PR))
                                    (GO L)))
                                LISTE-RESULTAT))))))
                    (RETURN (QUOTE OK)))))
    
                    ; -3- ;
                    ; REALISATION GRAMMAIRE ;
    DEFINE((
    
    (MIKROKOSMOS-II-39
        (LAMBDA (REF)
            (PROG ()
                (TERPRI)
            A   (PRINT REF)
                (MAP GRAMMAIRE
                    (QUOTE (LAMBDA (L)
                        (AND
                            (MATCH REF (CAAR L))
                            (SETQ REF (RPLACE (CADAR L)))
                            (GO A)))))
                (PRINT (QUOTE OK)))))
                
    (RPLACE
        (LAMBDA (L L1)
            (PROGN 
                (MAP L
                    (QUOTE (LAMBDA Y Z)
                        (SETQ L1 (NCONC L1
                            (COND 
                                ((ATOM (SETQ Z (CAR Y)))
                                (LIST Z))
                                (T (CDR (SASSOC (CAR Z)
                                    LISTE-RESULTAT)))
                            ))))))
                L1)))
    ))
    
    RPLACA (
        GRAMMAIRE
            (
                ((M20 B1 B2 M21 C2)         (C2 M20 B1 B2 #))
                ((C1 #)                     (C1 M10 B0 #))
                ((($?1) M10 B0 #)           (($?1) M11 B1 #))
                ((($?1) B1 #)               (($?1) B1 B2 #))
                ((($?1) M11 B1 B2 #)        (($?1) B1 B2 M21 #))
                ((($?1) M20 B1 B2 #)        (($?1) B1 B2 M10 #))
                ((C1 B1 B2 ($?2))           (M20 B1 B2 ($?2)))
                ((C2 B1 B2 ($?2))           (M11 B1 B2 ($?2)))
                ((M20 B1 B2 ($?1) #)        (M20 B1 B2 ($?1) C2 #))
                ((C3 #)                     (#))
                ((M11 B1 B2 ($?1) #)       (M11 B1 B2 ($?1) C3 #))
    ))
    
    ; -4- ;
    ; REALISATION GRAMMAIRE 2 ;
    DEFINE ((
    (MIKROKOSMOS-II-39
        (LAMBDA (REF)
        (PROG NIL
            (TERPRI)
        A   (PRINT REF)
            (SETQ REF (LINEARISER))
            (MAP GRAMMAIRE
                (QUOTE (LAMBDA (L)
                    (AND
                        (MATCH REF (CAAR L))
                        (SETQ REF (2RPLACE (CADAR L)))
                        (GO A)))))
            (PRINT (QUOTE OK)))))
            
    (LINEARISER
        (LAMBDA (L1)
            (PROGN
                (MAP REF
                    (QUOTE (LAMBDA (L Z)
                        (SETQ L1 (NCONC L1
                            (COND
                                ((ATOM (SETQ Z (CAR L)))
                                    (LIST Z))
                                (T (LIST (CAR Z)))))))))
                L1)))
    
    (2RPLACE
        (LAMBDA (L1 L2)
            (PROGN
                (MAP L1
                    (QUOTE (LAMBDA (L Z Y)
                            (SETQ L2 (NCONC L2
                                (COND
                                    ((OR
                                        (ATOM (SETQ Z (CAR L)))
                                        (NULL (SETQ Y (CDR
                                            (SASSOC (CAR Z)
                                            LISTE-RESULTAT)))))
                                     (LIST Z))
                                    (T (COND
                                        ((NULL (CDR Z)) Y)
                                    (T (PROGN
                                        (SETQ Z)
                                        (MAP Y
                                        (QUOTE (LAMBDA (L)
                                        (SETQ Z (NCONC Z
                                      (LIST (CONS (CAR L)
                                      (QUOTE *N*))))))))
                                      Z))))))))))
                ))            L2)))
    
    ; -5- ;
    
    RPLACA(
        GRAMMAIRE
            (     ; *  * ( . *N*) = INACTIF ;
            ((c1 #)
                ((C1 . *N*) M10 B0 #))
            ((($?1) M10 B0 #)
                (($?1 . *N*) M11 B1 #))
            ((($?1) B1 #)
                (($?1 . *N*) (B1 . *N*) B2 #))
            ((($?1) M11 B1 B2 #)
                (($?1 . *N*) (B1 . *N*) B2 M21 #))        
            ((($?1) M20 B1 B2 #)
                (($?1 . *N*) B1 (B2 . *N*) M10 #))
            ((C1 B1 B2 ($?2))
                ((M20 . *N*) (B1 . *N*) B2 ($?2)))
            ((C2 B1 B2 ($?2))
                (M11 B1 (B2 . *N*) ($?2)))
            ((($?1) B1 B2 M21 #)
                (($?1 . *N*) (B1 . *N*) (B2 . *N*) (M21 . *N*)
                C2 #))
            ((($?1) B1 B2 M10 #)
                (($?1) (B1 . *N*) (B2 . *N*) M10 C3 #))
            ((M20 B1 B2 M21 C2)
                (C2 M20 B1 B2 #))
            ))
    1 Comment
    2024/12/03
    19:46 UTC

    8

    SBCL interpreted vs compiled

    I’m successfully using sbcl with emacs/sly to develop the start of an opengl app. What is the difference between compiling a region vs evaluating a region ? I could understand if you compile-load the entire file, you should be generating object code (?) , but what is happening when you compile only a function or expression vs evaluation ? I’m a little confused over when you are using the interpreter vs compiler in the dev process.

    24 Comments
    2024/12/03
    17:27 UTC

    17

    What is the best way to learn lisp/scheme?

    I know that the best way to learn doesn't exist, but is there a roadmap for me to base my studies on or something like that?

    19 Comments
    2024/12/03
    17:23 UTC

    14

    Which Lisp is easiest to use with Rust?

    There are some lisps which are tailored for good integration and easy FFI for calling into C functions and extensions. Of the Schemes, Guile comes to my mind.

    Are there integrations that make it easier to call from Lisp or Scheme into Rust code? Perhaps like Python's PyO3? My impression is that Rust should mix very well with a functional Lisp style.

    My idea is a bit to use this for exploratory programming, writing stuff first in Lisp and then if needed, consolidating it into Rust code. Or, write a first implementation and comprehensive tests in Lisp, and then port the implementation to Rust but keep the same tests.

    Edit: One of Rusts primary advantage is its correctness guarantees:

    1. Guarantee that there is no undefined behaviour outside of code marked as unsafe
    2. Gurantee that there are no data race conditions, originating from mutating the same objects simultaneously from different threads

    Which Lisp implementations can give such a guarantee?

    18 Comments
    2024/12/03
    17:01 UTC

    12

    Does LISP has a standarized way of documenting projects? Maybe you are used to some sort of documentation prototyping.

    9 Comments
    2024/12/02
    08:19 UTC

    21

    Why is lisp so complex to setup?

    Another question I have is why is it so complex to get started with lisp? It seems so convoluted. Racket in comparison was very simple and straight forward. Click a download button and boom, your off to the races. It seems that python and other languages are also similarly straight forward. But with lisp, is like I am pulling my hair just to get started. Alot of the instruction I have found are not clear, or assume some knowledge of setting up environment. Comparing that to setting up python or Racket, with very clear and straight forward instruction with no assumptions of prior knowledge. With it complexity it seems as if learning/ working with lisp is just not beginner friendly.

    35 Comments
    2024/12/01
    19:24 UTC

    9

    Trying to learn lisp

    Trying to learn lisp and just getting started is proving extremely frustrating. I am looking for a literal step by step instruction on how to get started. I would prefer to work with SBCL and my only requirement for an editor is something that I can grow with long term. Please do not assume I have any knowledge of programing, computers, technology, etc. The only knowledge I have is enough to browse social media and work with office programs. In other words, I am an absolute beginner.

    My goal is to work through gentle introduction to symbolic computing, I prefer it over HTDP as it seems to be more suitable for the beginner in the most truest sense of the word. It also seems to be a better source for someone who is self teaching.

    Thanks for any assistance.

    7 Comments
    2024/12/01
    19:17 UTC

    20

    Category Theory in Programming

    Category Theory in Programming 

    https://racket.discourse.group/t/category-theory-in-programming/3375 the first present 🎁 in the Racket Advent Calendar #RacketAdvent2024

    Follow at https://racket.discourse.group/tag/advent-2024

    Thank you Noah ! 

    1 Comment
    2024/12/01
    16:48 UTC

    5

    Cannot install alive in vscode Component :ALIVE-LSP not found

    I followed the instructions to install Alive in VSCode from the marketplace link:
    https://marketplace.visualstudio.com/items?itemName=rheller.alive
    I think I installed everything needed.

    • (ql:quickload "bordeaux-threads") To load "bordeaux-threads": Load 1 ASDF system: bordeaux-threads ; Loading "bordeaux-threads"("bordeaux-threads")
    • (ql:quickload "usocket") To load "usocket": Load 1 ASDF system: usocket ; Loading "usocket"("usocket")
    • (ql:quickload "cl-json") To load "cl-json": Load 1 ASDF system: cl-json ; Loading "cl-json"("cl-json")
    • (ql:quickload "flexi-streams") To load "flexi-streams": Load 1 ASDF system: flexi-streams ; Loading "flexi-streams"("flexi-streams")

    However, I am still encountering the following error:

    debugger invoked on a ASDF/FIND-COMPONENT:MISSING-COMPONENT in thread
    #<THREAD tid=259 "main thread" RUNNING {70083E05B3}>:
      Component :ALIVE-LSP not found

    I could not find any solutions for this specific error online. Also, Alive-LSP is not listed as a requirement in the documentation.

    I tried installing alive-lsp manually, but encountered this error:

    sqlCopy codegit@github.com:nobody-famous/alive-lsp.git $QUICKLISP_HOME/local-projects/alive-lsp  
    fatal: could not create leading directories of '/local-projects/alive-lsp': Read-only file system

    What should I do to install Alive in VSCode, or should I give up on VSCode and switch to Emacs instead?

    9 Comments
    2024/12/01
    06:45 UTC

    8

    Advent of Code 2024 Leaderboard

    4 Comments
    2024/11/29
    22:16 UTC

    9

    AutoCAD LISP

    Hi everyone,

    I'm a land surveyor and need help. I would like to know if any good samaritans are familiar with AutoCAD LISP. I need to add a few lines of code to an existing LISP. Can anyone help me?

    5 Comments
    2024/11/28
    18:05 UTC

    58

    Preparing for a Possible Complete Internet Shutdown in My Country.

    So there are civil unrests happening in my country. They have already partially blocked the internet there are rumors that if the situation doesn't get any better they just might shut down the whole internet.
    I have already download some things for offline use but if you have any suggestions related to lisp that might be useful when the internet is down for God knows how long please list them so i can download them for offline viewing.

    Extra resources, links or blogs about things more general are also appreciated.

    48 Comments
    2024/11/28
    12:37 UTC

    12

    CL-Protobufs Supports editions! (2023)

    0 Comments
    2024/11/27
    13:57 UTC

    32

    Lisp, or...

    Probably not the most original post in this subreddit or any other programming language subreddit, but I really need some advice.

    I was studying the book "Common Lisp: A Gentle Introduction to Symbolic Computation" everyday, and stopped at the chapter of recursion after my work schedule changed (I don't work with programming, yet). I really liked the language, on how easy it was to express my ideas than it was when I tried Python or C (never could get past the basic terminal programs, lol).

    Some days after this, I grabbed a book named 'Programming from Ground Up', and the author of this book was somewhat frustrated that introductory programming books didn't taught how computers worked. And then I thought: "Well, not even I know!" And so, I am at crossroads.

    Should I keep learning Lisp and it's concepts, or go to Assembly/C?

    I could never get past the basics of any language (lol), probably it's a mindset issue, whatever. But I want advice so I can see what's the best path I could take. I really want to enter into low code languages and game development, but Lisp is a higher level language... And most of the game libraries I've seen on Lisp 'depends' on C/C++ knowledge. Like SDL2, Vulkan, OpenGL... Etc.

    Anyway, sorry for the messy text. 🦜

    32 Comments
    2024/11/26
    14:31 UTC

    11

    Easy-ISLisp ver5.38

    Hello everyone,
    I have released Easy-ISLisp v5.38. This is a bug fix release. It was discovered that there was an issue with the distributed parallel functionality on Raspberry Pi. Please refer to the release notes for more details. https://github.com/sasagawa888/eisl/releases/tag/v5.38

    0 Comments
    2024/11/25
    09:22 UTC

    27

    Why Genera failed ?

    Hi dear community users , as the title says ? and if there is any viable alternative currently besides portable Genera ?

    26 Comments
    2024/11/24
    14:15 UTC

    11

    Racket meet-up: Saturday, 7 December, 2024

    Everyone is welcome to join us for the Racket meet-up: Saturday, 7 December, 2024 at 18:00 UTC

    Announcement at https://racket.discourse.group/t/racket-meet-up-saturday-7-december-2024/3353

    EVERYONE WELCOME 😁

    0 Comments
    2024/11/24
    11:54 UTC

    4

    Matrix/Vector class with operator overloading.

    In C++ it is convenient to use a library like GLM to do matrix math using operator overloading. For example (pseudocode)

    // Create transformation matrices and multiply them
    //
    glm::mat4 translateMatrix = glm::translate(....);
    glm::mat4 rotateMatrix = glm::rotate(...);
    glm::mat4 transformMatrix = translateMatrix * rotateMatrix;
    
    // Mutiply a vector by a matrix
    glm::vec4 point = glm::vec4(4, 5, 6, 1.0);
    glm::vec4 tranformedPoint = transformMatrix * point;

    etc.

    Suggestions for the best way to implement natively in LISP ? So far, I am liking what I see in CLOS and according to google, it supports operator overloading - so I am wondering if this is the best approach ? Maybe there is an existing CL library that supports exactly what I need and I am reinventing the wheel ?

    4 Comments
    2024/11/23
    19:46 UTC

    3

    Using method combinations to create an ordered pipeline - impossible?

    Hey everyone,

    as part of trying to get my hands dirty with the more subtle parts of CLOS, I set myself the (purely pedagogical) task of creating a method combination that would emulate an ordered pipeline.

    The aim was to have each method constrained to have identical input & output shapes, and the output from one implementation would be piped into the next applicable one. I also wanted some way to order the methods, preferably by somehow specifying a number as part of the method definition - then, the implementations would be chained with respect to this order.

    The result would allow me to do something like

    (defgeneric asset-pipeline (file-path file-contents)
        :method-combination pipeline)
    (defmethod asset-pipeline 10 (file-path file-contents)
        "Minify CSS files"
        (list file-path (minify file-contents)))
    (defmethod asset-pipeline 20 (file-path file-contents)
        "Fingerprint file names"
        (list (fingerprint file-path) file-contents))

    However, I've come to the conclusion that this is actually impossible (using method combinations), and I just wanted to run my thinking by the community to see if I'm understanding everything correctly.

    • Since I want to emulate a pipeline, I can't require each implementation to be specialized in some parameter - the input (and output) signatures need to be the same for every implementation

    • Therefore, in order to avoid a "More than one method with the same specializers" error being signaled, I would need to separate each method into a separate method group, e.g. by the specified priority. However, I can't do that, because the number of method group list is, by definition, static - I either need to enumerate the symbols, or include a predicate, the former not being applicable, and the latter causing clashes due to all implementations having the same specificity

    Am I getting this right, or am I missing something?

    EDIT: To clarify: I'm operating under the assumption that if I define two (or more) defmethods with the same specificity in the same method group (that is having the same qualifiers), the code will signal an error.

    Taking the example from the CLHS:

    (defun positive-integer-qualifier-p (method-qualifiers)
       (and (= (length method-qualifiers) 1)
            (typep (first method-qualifiers) '(integer 0 *))))
    
    (define-method-combination pipeline ()
      ((methods positive-integer-qualifier-p))
      `(progn ,@(mapcar #'(lambda (method)
                            `(call-method ,method))
                        (stable-sort methods #'<
                                     :key #'(lambda (method)
                                              (first (method-qualifiers method)))))))
    
    
    (progn
      (defgeneric process-data (input)
        (:method-combination pipeline))
      (defmethod process-data 20 (input)
                 (format t "Processing string second: ~a~%" input))
      (defmethod process-data 10 (input)
                 (format t "Processing string first: ~a~%" input)))
    CL-USER> (process-data "abc")
    ; Evaluation aborted on #<SB-PCL::LONG-METHOD-COMBINATION-ERROR "More than one method of type ~S ~
    ;                                        with the same specializers." {100174CB93}>.

    Therefore, I would need to somehow define a separate method group for each possible priority, so defmethod process-data 20 is part of a different group then defmethod process-data <any other number>. But since there are an infinite number of possible number, and therefore groups, I can't do that either, because AFAIK there's no way to specify the groups dynamically. They need to be statically enumerated by explicitly writting out either the keywords or predicates that identify them. Therefore, in the previous example, we're defining a single group, but we what we actually need to do is define a separate group for each number that's used.

    This is why I've come to the conclusion that it's impossible.

    10 Comments
    2024/11/23
    17:11 UTC

    5

    X-Post: I'm Reviewing Comp Sci Textbooks using Scheme - Please Recommend Good or Unique Ones

    2 Comments
    2024/11/23
    02:09 UTC

    9

    Repl hangs after exit

    I’m running a small graphics program using glfw3 in emacs/slime/sbcl.

    I create a window , draw a box and exit when a key is pressed. After learning that graphics can’t run in the main thread on macOS , I used “trivial-main-thread” to solve that problem. So now the program can be started in the repl and I can modify the program ( such as changing colors of the box) while the program is running using eMacs and slime . Fantastic!

    The only problem is that when I exit the lisp code , but hitting a key ( and the window is closed ) , the lisp process doesn’t appear to terminate and I the repl hangs. I have to kill the sbcl process and restart slime .

    I thought maybe this is a known Mac issue , but I downloaded Kaveh’s Kons-9 project and ran it under slime / eMacs ( it also uses glfw3 and same trivial-thread package, but it doesn’t hang the repl . I looking at the code, it doesn’t appear I’m doing anything different ( but I’m a novice lisper so could be I’m missing something.

    Anyone know what is next approach to debug ?

    Code (appolgies for the formatting :

    (ql:quickload :cl-opengl)
    (ql:quickload :cl-glfw3)
    (ql:quickload :trivial-main-thread)
    
    (in-package :cl-glfw3)
    
    (def-key-callback quit-on-escape (window key scancode action mod-keys) 
       (declare (ignore window scancode mod-keys)) 
       (when (and (eq key :escape) (eq action :press)) (set-window-should-close)))
    
    (defun render () 
       (gl:clear :color-buffer) 
       (gl:with-pushed-matrix (gl:color 1 0 9) 
       (gl:rect -25 -25 25 25)))
    
    (defun set-viewport (width height) 
       (gl:viewport 0 0 width height) 
       (gl:matrix-mode :projection)    
       (gl:load-identity) (gl:ortho -100 100 -50 50 -1 1) 
        (gl:matrix-mode :modelview) (gl:load-identity))
    
    (def-window-size-callback update-viewport (window w h) (
        declare (ignore window)) 
         (set-viewport w h))
    
    (defun basic-window-example ()
     (sb-int:with-float-traps-masked
        (:invalid
         :inexact
         :overflow
         :underflow
         :divide-by-zero))
      (with-init-window (:title "Window test" :width 600 :height 400)
      (setf %gl:*gl-get-proc-address* #'get-proc-address)
      (set-key-callback 'quit-on-escape)
      (set-window-size-callback 'update-viewport)
      (gl:clear-color 0 0 0 0)
      (set-viewport 600 400)
      (loop until (window-should-close-p)
         do (render)
         do (swap-buffers)
            do (poll-events))
      (format t "loop ended")
      (terminate)))
    
    (defun run () (
        trivial-main-thread:call-in-main-thread 
          (lambda () (sb-int:set-floating-point-modes :traps nil) 
           (basic-window-example))))
    
    (run)
    8 Comments
    2024/11/22
    18:23 UTC

    Back To Top