←back to thread

89 points Numerlor | 1 comments | | HN request time: 0.199s | source
Show context
behnamoh ◴[] No.41851517[source]
I want a Lisp-like REPL for my Python programs that is available to the user who runs my compiled Python program (so, I want compilation as well). The user will be able to interact with my program (instead of just running the main function), change function definitions, etc. and mold the program to their specific use case while it's running.
replies(5): >>41851780 #>>41852247 #>>41852604 #>>41853249 #>>41853727 #
ks2048 ◴[] No.41851780[source]
Some things are a bit awkward, but what specifically can't you really do in a Python REPL? You can dynamically overwrite functions in an imported module, you can re-import modules with importlib, etc. I ask because my Lisp experience is limited.
replies(1): >>41851857 #
behnamoh ◴[] No.41851857[source]
Lisp REPL keeps the state of the program because it is a live image. With Python REPL you need to rerun the program to set the variables to their values.
replies(1): >>41852345 #
ks2048 ◴[] No.41852345[source]
You can create a file, example.py:

    import time
    value = "foo"
    def go():
      for i in range(10):
        print("...", i, value)
        time.sleep(3)
Then, in repl,

    import example
    import threading
    thread = threading.Thread(target=example.go)
    thread.start()
It will slowly print out messages and you can do "example.value = 'bar'" in the REPL and it will change.
replies(3): >>41852396 #>>41853872 #>>41854578 #
handman ◴[] No.41854578[source]
This is nothing like the Lisp debugger. It is very hard to convince Pythonistas of the fact:

https://news.ycombinator.com/item?id=36888648

replies(1): >>41854724 #
ks2048 ◴[] No.41854724[source]
Interesting thread. I only read some of it, but I did find one answer that tells me how Python and LISP differ:

  As an example, I suppose that when you’re developing code in Python’s pseudo-REPL you often reimport a file containing class definitions. When you do that, what happens to all the old objects with the old  class definition? Nothing, they still belong to the old class.

  ...

  In Lisp, it’s different. There is a defined protocol for what happens when a class is redefined. Every single object belonging to the old class gets updated to the new class.
replies(2): >>41854922 #>>41855975 #
1. behnamoh ◴[] No.41854922[source]
> In Lisp, it’s different. There is a defined protocol for what happens when a class is redefined. Every single object belonging to the old class gets updated to the new class.

This. Lisp gives you ultimate power but of course, it means it unlocks more ways to shoot yourself in the foot in the process. Most organizations don't want "smart hacky" solution (i.e., they don't want you as the programmer to fix issues in creative ways that Lisp provides to you), instead, they want "standard processes" that can be taught to new hires (i.e., they want you as the programmer to write standard, idiomatic code that everyone understands). The latter comes at the cost of less flexibility (i.e., when your rock solid code crashes, it means you must update the source code instead of fixing it on the go like in Lisp restarts).