Live data from Hacker News

Common Lisp's block / return-from and unwind-protect

axisofeval.blogspot.com

21–30 of 63 posts

Re: Common Lisp's block / return-from and unwind-protect

#21
post #20

Earlier quoted context omitted.

Longjmp in standard C, swapcontext in POSIX C. I think GCC allows gotos to the containing function from a local function (but I never used GCC local functions). Smalltalk, and I believe ruby, allow non local return from blocks.

longjmp simply restores the machine registers (including PC and SP) and thus doesn’t respect any sort of unwind-protect, a concept unknown in C. unwind-protect is a more general form of the c++ raii (in fact c++ got raii from Common Lisp).

`longjmp` does not restore the machine registers on all platforms. The C standard guarantees only the contents of variables marked `volatile`: anything above that is implementation-dependent.

I think that MSVC++ longjmp actually does proper unwinding, calling destructors in C++ functions on the stack, but don't quote me on that. I think it is also dependent on the compiler flags.

Re: Common Lisp's block / return-from and unwind-protect

#22

Gah, another Lisp post to tempt me to add yet another mini project to my plate...I always am curious about trying more Lisp because I keep seeing commentary about how powerful it is to actually build applications once you get moving on building things. Anyone here have any recent practical experience in this direction who would confirm this in Lisp vs in other programming languages? Does effort in Lisp really compoun…

I'm learning programming at age fifty-four and have chosen Common Lisp as my one language for life. If you want something easy to learn with a ton of support pick Python, Elixir, and/or JS. CL sucks for mini-projects since the learning curve requires serious commitment and is SO different from what people are used to. CL requires a long-term commitment and demands the programmer challenge pop programming trends and d…

“not get freaked out using some libs that are stable and haven't been updated in years”

In this vein, it’s great that decades-old Common Lisp books are still current. The paucity of Web content is not as bad as it seems: you can get a real book.

Re: Common Lisp's block / return-from and unwind-protect

#23

Gah, another Lisp post to tempt me to add yet another mini project to my plate...I always am curious about trying more Lisp because I keep seeing commentary about how powerful it is to actually build applications once you get moving on building things. Anyone here have any recent practical experience in this direction who would confirm this in Lisp vs in other programming languages? Does effort in Lisp really compoun…

I'm learning programming at age fifty-four and have chosen Common Lisp as my one language for life. If you want something easy to learn with a ton of support pick Python, Elixir, and/or JS. CL sucks for mini-projects since the learning curve requires serious commitment and is SO different from what people are used to. CL requires a long-term commitment and demands the programmer challenge pop programming trends and d…

+1 nice summary! I have been using Common Lisp since the early 1980s and I also love the language. For my own Lisp hacking pleasure, I add a few Schemes to the mix, but that is often a (fun) distraction for me, and I would be better off sticking with CL (or Python for deep learning projects).

Do you have a blog where you share your learning experiences?

Re: Common Lisp's block / return-from and unwind-protect

#24

Gah, another Lisp post to tempt me to add yet another mini project to my plate...I always am curious about trying more Lisp because I keep seeing commentary about how powerful it is to actually build applications once you get moving on building things. Anyone here have any recent practical experience in this direction who would confirm this in Lisp vs in other programming languages? Does effort in Lisp really compoun…

I've written a few small CL web applications( with about 100 users active a day), along with a few terminal applications (with only ~10 users). Other languages I know is C , Erlang, Elixir and a bit of python. This will end up sounding a bit evangelical but so be it. I feel that the lisp code was easier to write and reason about, the being able to hot reload code from the repl significantly decreased the time to comp…

I'd rather say there is a definite cult over lisp. But it's very different from the other languages which I'd qualify as rather hardcore. Lisp's cult is a magical cult. No other language as such amazing stories as the space probe remotely debugged from earth with a repl, the extreme hot reload and mystical intertwining of assembly on PS2 of Jak & Daxter's GOAL, the MIT course with a Fantasia level of teaching, The symbolic machines, etc.

The only other language like that I can think of is smalltalk.

Re: Common Lisp's block / return-from and unwind-protect

#25
post #20

Earlier quoted context omitted.

Longjmp in standard C, swapcontext in POSIX C. I think GCC allows gotos to the containing function from a local function (but I never used GCC local functions). Smalltalk, and I believe ruby, allow non local return from blocks.

longjmp simply restores the machine registers (including PC and SP) and thus doesn’t respect any sort of unwind-protect, a concept unknown in C. unwind-protect is a more general form of the c++ raii (in fact c++ got raii from Common Lisp).

Implementing exception handling (with cleanup on unwind) on top of setjmp was not uncommon. GCC still does on some targets. But I'm sure you know this more than I do.

I think that RAII is different from unwind-protect and other scope based cleanup (finally, defer, with) as it is tied to object lifetimes. The fact that automatic objects lifetimes are tied to scope is a nice feature, but RAII goes beyond that.

Re: Common Lisp's block / return-from and unwind-protect

#26

Earlier quoted context omitted.

I'm learning programming at age fifty-four and have chosen Common Lisp as my one language for life. If you want something easy to learn with a ton of support pick Python, Elixir, and/or JS. CL sucks for mini-projects since the learning curve requires serious commitment and is SO different from what people are used to. CL requires a long-term commitment and demands the programmer challenge pop programming trends and d…

+1 nice summary! I have been using Common Lisp since the early 1980s and I also love the language. For my own Lisp hacking pleasure, I add a few Schemes to the mix, but that is often a (fun) distraction for me, and I would be better off sticking with CL (or Python for deep learning projects). Do you have a blog where you share your learning experiences?

OMG! This is what I'm talking about with Common Lisp. One minute you're a washed-up slacker, the next Mark L. Watson speaks to you. I'm winding my way through "Loving Common Lisp, or the Savvy Programmer's Secret Weapon" as we speak and loving it. Thank you!

I don't have a blog and haven't gotten far enough in my learning to make anything useful, but I do plan to produce a newbie's guide to help people get started quickly. My perspective as an older person for whom CL is my first language could be valuable since my sticking points are different and I don't yet have bad habits to break.

Re: Common Lisp's block / return-from and unwind-protect

#27
post #20

Earlier quoted context omitted.

Longjmp in standard C, swapcontext in POSIX C. I think GCC allows gotos to the containing function from a local function (but I never used GCC local functions). Smalltalk, and I believe ruby, allow non local return from blocks.

longjmp simply restores the machine registers (including PC and SP) and thus doesn’t respect any sort of unwind-protect, a concept unknown in C. unwind-protect is a more general form of the c++ raii (in fact c++ got raii from Common Lisp).

>> in fact c++ got raii from Common Lisp

I know and understand this is true.

Can you point to any sources (projects, papers) that further substantiate this?

Re: Common Lisp's block / return-from and unwind-protect

#28
post #12

Earlier quoted context omitted.

One of the only languages where I saw this non-local returns is Kotlin. You can return from a function from within a lambda (and I believe this works on any number of levels), for example: fun go(list: List ): Boolean { list.forEach { if (it.isEmpty()) return@go true } return false }

Longjmp in standard C, swapcontext in POSIX C. I think GCC allows gotos to the containing function from a local function (but I never used GCC local functions). Smalltalk, and I believe ruby, allow non local return from blocks.

Smalltalk only allows the return from the block's lexically enclosing method, not an arbitrarily specifiable context like Common Lisp does. It's discussed a bit on c2.com [1]

[1] https://wiki.c2.com/?SmalltalkBlockReturn

Re: Common Lisp's block / return-from and unwind-protect

#29
post #17

Earlier quoted context omitted.

I'm learning programming at age fifty-four and have chosen Common Lisp as my one language for life. If you want something easy to learn with a ton of support pick Python, Elixir, and/or JS. CL sucks for mini-projects since the learning curve requires serious commitment and is SO different from what people are used to. CL requires a long-term commitment and demands the programmer challenge pop programming trends and d…

You have an extremely deep understanding of the discipline of computer programming for someone who has only just started to learn!

How kind of you to say. I held off on learning programming for so long due to my visceral disgust with C/UNIX and ALGOL syntax. I just knew it was the wrong set of abstractions that have trapped us all in a grey hellscape of mediocrity and wasted potential. When I was a kid I turned turtles into a spirograph in Logo on an Apple II. It ruined me. I didn't know Logo was functional or Lisp-inspired.

When I found functional programming in Erlang I got SO excited. When I found Common Lisp, decades of pent-up frustration melted away and I knew I'd come home. I guess my Unix Hating led to some intuitive thinking over the years and I've been making up for lost time over the past couple of years and mapping what I knew I wanted to what has been there in CL all along.

Re: Common Lisp's block / return-from and unwind-protect

#30
post #8

Earlier quoted context omitted.

Could you clarify what you mean by 'there is nothing new under the sun' when referring to programming with Common Lisp? Are you indicating that Lisp has already introduced many of the concepts and features that are now found in modern programming languages, implying that contemporary languages have largely assimilated Lisp's ideas and paradigms? Your comment left me with a strange sentiment. I'm somewhat disheartenin…

> Are you indicating that Lisp has already introduced many of the concepts and features that are now found in modern programming languages, implying that contemporary languages have largely assimilated Lisp's ideas and paradigms? Yes. See effect handlers for an example, which are making rounds around the programming world as of late. They are equivalent to the Lisp condition system, except formalized to work in stron…

> They are equivalent to the Lisp condition system

Not exactly correct due to the lack of higher order effects (https://news.ycombinator.com/item?id=20513370), but the condition system is "good enough" for a lot of use cases

Post reply on HN