6 ms·
How does it look like in Python? In Lisp: CL-USER 43 > (+ 1 (foo 20)) Error: Undefined operator FOO in form (FOO 20). 1 (continue) Try invoking FOO ag
by lispm 3y ago
How does it look like in Python? In Lisp:
CL-USER 43 > (+ 1 (foo 20))
Error: Undefined operator FOO in form (FOO 20).
1 (continue) Try invoking FOO again.
2 Return some values from the form (FOO 20).
3 Try invoking something other than FOO with the same arguments.
4 Set the symbol-function of FOO to another function.
5 Set the macro-function of FOO to another function.
6 (abort) Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
CL-USER 44 : 1 > (defun foo (a) (+ a 21))
FOO
CL-USER 45 : 1 > :c 1
42
Note that we are not in some debug mode, to get this functionality. It also works for compiled code.
Lisp detects that FOO is undefined. We get a clear error message.
Lisp then offers me a list of restarts, how to continue.
It then displays a REPL one level deep in an error.
I then define the missing function.
Then I tell Lisp to use the first restart, to try to invoke FOO again. We don't want to start from scratch, we want to continue the computation.
Lisp then is able to complete the computation, since FOO is available now.
- mathisfun123 3y ago>Note that we are not in some debug mode, to get this functionality. Jesus Christ I swear it's like you ascribe mysterious powers to the parens. Do you think the parens give you the ability to travel through time or reverse the pc or what? Okay it's not in a debug mode but it's in a "debug mode". Like seriously tell me how you think this works if it's not effectively catching/trapping some sigkill or something that's the equivalent thereof? I have never in my life met this kind of intransigence on just manifestly obvious things.
- _19qg 3y agoCommon Lisp programs run by default in a way that calls to undefined functions are detected. Here the Lisp simply tries to look up the function object from the symbol. There is no function, so it signals a condition (aka exception). The default exception handler gets called (without unwinding the stack). This handler prints the restarts and calls another REPL. I define the function -> the symbol now has a function definition. We then resume and Lisp tries again to get the function definition. The computation continues where we were. That's the DEFAULT behavior you'll find in Common Lisp implementations.
- mathisfun123 3y ago>Common Lisp programs run by default in a way that calls to undefined functions are detected. Cool so what you're telling me is that by default every single function call incurs the unavoidable overhead of indirecting through some lookup for a function bound to a symbol. And you're proud of this?
- ghfwlc 3y agoCompared to Python, Common Lisp hardly has any performance issues.
- mathisfun123 3y agoOkay well when pytorch, tensorflow, pandas, Django, flask, numpy, networks, script, xgboost, matplotlib, spacy, scrapy, selenium get ported to lisp, I'll consider switching (only consider though since the are probably at least another 20 python python packages that I couldn't do my job without).
- svetlyak40wt 3y agoThat is a typical consumerism: "Give me everything ready to use and then I'll use it." How about bringing some value to the community?
- rwxrwxrwx 3y agoFor the sake of anyone reading this thread who isn't in the know: many of these libraries are really written in C/C++ and have Python bindings.
- mathisfun123 3y agoi said ported not implemented; the likelihood that any of those libraries sprout lisp bindings is about as likely as them being rewritten in lisp. so it's the same thing and the point is clear: i don't care about some zany runtime feature, i care about the ecosystem.
- sireat 3y agoHmm, what advantage does Lisp offer here over Python? >>> 1 + foo(20) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'foo' is not defined >>> def foo(a): ... return a + 21 File "<stdin>", line 2 return a + 21 ^ IndentationError: expected an indented block >>> def foo(a): ... return a + 21 ... >>> 1 + foo(20) 42 >>> Mind the hilarious indentation error, as I had not touched the old-school REPL in ages. In normal day to day operations, I do the same thing daily with Jupyter Notebooks. I get access to as much state as I need. With notebooks workflow it is normal to forget to define something and then redefine in the next cell. You could redefine function signatures etc. Ideally then you move cells in the correct order so that code can be used as Run All. I "feel" ridiculously productive in VS Code with full Notebook support + copilot. I can work across multiple knowledge domains with ease (ETL across multiple database technologies, NLP-ML, visualization, web scraping, etc) Underneath it is same as working in old school Python REPL just with more scaffolding.
- lispm 3y agoFrom what I see in your example, you invoke the form again. In Common Lisp you don't need that. You can stay in a computation and fix&resume from within.
- kgwgk 3y ago> Hmm, what advantage does Lisp offer here over Python? It does have a clear advantage if instead of (+ 1 (foo 20)) we were doing (+ (long-computation-answering-the-ultimate-question-of-life-the-universe-and-everything) (foo 20)) (Reminder: we're dicussing Common Lisp here.)
- momentoftop 3y agoI have been playing again with CL recently and am doing some trivial web-scraping of an old internet forum. I don't use a REPL directly, but just have a bunch of code snippets in a lisp file that I tell my editor to evaluate (similar to Jupyter?). I haven't bothered doing any exception (condition) handling, and so this morning I found this in a new window: Condition USOCKET:TIMEOUT-ERROR was signalled. [Condition of type USOCKET:TIMEOUT-ERROR] Restarts: 0: [RETRY-REQUEST] Retry the same request. 1: [RETRY-INSECURE] Retry the same request without checking for SSL certificate validity. 2: [RETRY] Retry SLIME interactive evaluation request. 3: [*ABORT] Return to SLIME's top level. 4: [ABORT] abort thread (#<THREAD tid=17291 "worker" RUNNING {1001088003}>) plus the backtrace. This is in a loop that's already crawled a load of webpages and has some accumulated some state. I don't want a full redo (2), so I just press 0. The request succeeds this time and it continues as if nothing happened.