1

For a project I need the output of a Lisp program, however I have never heard of Lisp before and I cannot make it run. I have downloaded the file (.lsp) from a website and looked at it with a texteditor to understand its logic. The lisp file gets a certain input and reduces that input through some iterative steps. I want to know not only the output but also the iteratrion process, which is why a logfile of that would be great. I have downloaded Portacle and some other Lisp interpreters/compilers, but I cannot make it work. It is so frustrating. Is there a simple way to run a lisp file from a directory? I have watched several tutorials and read thorugh some threads here, but I have still no clue how to run the Lisp file like I would run a Python file.

I am so immensely grateful for any help! I am pretty sure there is a simple way that I am just not seeing. Thank you so much in advance!

PyCod1297
  • 37
  • 5
  • 1
    I would recommend that you install sbcl on your os and check its documentation for running scripts. If I remember correctly there is all the info you need. Portacle is a complete IDE which includes sbcl but might be too much for your tasks. – Martin Buchmann Feb 10 '21 at 12:46
  • 1
    Without knowing what the program is this is very hard to answer. Lisp is a whole family of languages, and code for even one member of the family may or may not be written in a way so that it can usefully be run from an OS command-line (since Lisps are generally conversational languages, so many programs are written to be run from within Lisp). –  Feb 10 '21 at 12:50
  • Thanks a lot! Portacle did overwhelm me a bit to be honest. This is the lisp program I am using http://modeltheory.org/programs/BooleanConcepts.lisp and I managed to run in with an online compiler. However, I am wondering if it is even possible to get a logfile since the code does not have any logging commands. Do I need to add something or can I just log the program's iteration steps? – PyCod1297 Feb 10 '21 at 12:58
  • The style of this code seems quite questionable to me, and not very helpful for learning. Also, it seems that (all?) outputs of the program are appended as comments further down in the file, so you might not need to run it yourself. – Svante Feb 13 '21 at 00:29

1 Answers1

5

If you have to spend some time working on this, it is worth installing at least Quicklisp and Slime, following this tutorial:

https://lisp-lang.org/learn/getting-started/

You can however start with only the interpreter. You need to install sbcl, and I recommend having rlwrap too because SBCL prompt does not have fancy readline features.

$ rlwrap sbcl

Then, you'll be in a Lisp REPL. Execute this to ensure the code is compiled with the maximum level of debugging:

* (sb-ext:restrict-compiler-policy 'debug 3)

The environment should reply with:

((DEBUG . 3))
NIL

Then, you can compile your input file (use an absolute path, or a path relative to the directory where you stared sbcl):

* (compile-file "/tmp/concepts")

A lot of text will be emitted, but the interpreter replies with the name of the object file being produced (e.g. "/tmp/concepts.fasl"), you can load it by supplying * as an argument, since the asterisk means the last result.

* (load *)

Following the comments in the file (between #| and |#), you can test it as follows:

* (test-concepts shepard)

This performs a lot of tests.

You can trace individual functions if you want with (trace X Y Z) where X , Y and Z are function names (you can also untrace them). To simplify, here is a list where all (I think) symbols described in the comments are traced:

(trace frequency-of-properties
       frequency-of-pairs
       count-of-n
       simplify-eight
       remove-non-minimals
       replace-lis-in-concept
       print-linear-models
       simplify-quads
       make-master-list
       make-pairs-for-quads
       find-pair-quads
       memberprop-lis
       max-length
       count-of-n
       frequency-of-pairs
       find-pairs-that-simplify
       find-pair-to-simplify
       remove-non-minimals
       triples 
       three-pairs 
       simplify-by-mates
       doubles
       co
       remove-non-minimals
       replace-lis-in-concept
       simplify-by-mates
       singles
       remove-non-minimals
       replace-lis-in-concept
       simplify-by-mates
       print-linear-models
       simplify-by-mates)

Using the same test as above, the last test prints the following trace:

Problem 6   0: (PRINT-LINEAR-MODELS (((A) (B) (- C)) ((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))))
AB-C A-BC -ABC -A-B-C 
  0: PRINT-LINEAR-MODELS returned NIL

  0: (FREQUENCY-OF-PROPERTIES (((A) (B) (- C)) ((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))))
  0: FREQUENCY-OF-PROPERTIES returned
       ((((A)) 2) (((B)) 2) (((- C)) 2) (((- B)) 2) (((C)) 2) (((- A)) 2))
  0: (COUNT-OF-N ((((A)) 2) (((B)) 2) (((- C)) 2) (((- B)) 2) (((C)) 2) (((- A)) 2)) 4)
    1: (COUNT-OF-N ((((B)) 2) (((- C)) 2) (((- B)) 2) (((C)) 2) (((- A)) 2)) 4)
      2: (COUNT-OF-N ((((- C)) 2) (((- B)) 2) (((C)) 2) (((- A)) 2)) 4)
        3: (COUNT-OF-N ((((- B)) 2) (((C)) 2) (((- A)) 2)) 4)
          4: (COUNT-OF-N ((((C)) 2) (((- A)) 2)) 4)
            5: (COUNT-OF-N ((((- A)) 2)) 4)
              6: (COUNT-OF-N NIL 4)
              6: COUNT-OF-N returned NIL
            5: COUNT-OF-N returned NIL
          4: COUNT-OF-N returned NIL
        3: COUNT-OF-N returned NIL
      2: COUNT-OF-N returned NIL
    1: COUNT-OF-N returned NIL
  0: COUNT-OF-N returned NIL
  0: (SIMPLIFY-BY-MATES (((A) (B) (- C)) ((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))))
    1: (MAX-LENGTH (((A) (B) (- C)) ((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))))
      2: (MAX-LENGTH (((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))) 3)
        3: (MAX-LENGTH (((- A) (B) (C)) ((- A) (- B) (- C))) 3)
          4: (MAX-LENGTH (((- A) (- B) (- C))) 3)
            5: (MAX-LENGTH NIL 3)
            5: MAX-LENGTH returned 3
          4: MAX-LENGTH returned 3
        3: MAX-LENGTH returned 3
      2: MAX-LENGTH returned 3
    1: MAX-LENGTH returned 3
  0: SIMPLIFY-BY-MATES returned NIL
No simplification possible.  Number of models 4

This should give a better understanding of what is happening. You can also use (step (test shepard)), in which case the execution breaks in the debugger; use help to have more information about the commands you can invoke. For example you can write STEP (or just S) to step into an expression, NEXT to skip over an expression and go to the next one, OUT to step out of the current frame, etc.

coredump
  • 37,664
  • 5
  • 43
  • 77