News for hackers. Stuff that matters.
Re:Racket: The Lisp for the Modern Day by mejutoco on Thursday June 29, 2023 @09:21AM (#36519993)
IMHO Common Lisp is the modern one. Using the JVM is nice for certain uses, and clojure is a fine language, but going bare metal from higher abstractions is some power of Lisp that we should not give up. Same with macros and code generation.

Luckily all of them can coexist, so we do not need to choose.

Re:Racket: The Lisp for the Modern Day by dom2 on Thursday June 29, 2023 @09:42AM (#36520274)
There is also ABCL, an implementation of common lisp on the JVM https://armedbear.common-lisp.dev/
Re:Racket: The Lisp for the Modern Day by freilanzer on Friday June 30, 2023 @07:06AM (#36532877)
And it has a great name: Armed Bear Common Lisp.
Re:Racket: The Lisp for the Modern Day by criddell on Thursday June 29, 2023 @09:39AM (#36520224)
How is code generation handled on modern operating systems and CPUs? Isn't there normally a strict separation between code and data to prevent exploits?
Re:Racket: The Lisp for the Modern Day by andsoitis on Thursday June 29, 2023 @09:59AM (#36520452)
> How is code generation handled on modern operating systems and CPUs? Isn't there normally a strict separation between code and data to prevent exploits?

You compile code, which is text (data), all the time, don’t you?

Re:Racket: The Lisp for the Modern Day by Zambyte on Thursday June 29, 2023 @10:52AM (#36521191)
The difference is that the output of the compiler is usually not loaded into the same process that did the compiling. That is not the case for applications that are developed On Lisp™.
Re:Racket: The Lisp for the Modern Day by andsoitis on Friday June 30, 2023 @12:27AM (#36530491)
True. Well, since it works on the latest CPUs and OS's, presumably it isn't verboten.
Re:Racket: The Lisp for the Modern Day by p_l on Thursday June 29, 2023 @10:04AM (#36520500)
At worst you have to ensure that you separate what needs to be writeable from executable, and then flip mappings RW->RX when generating new code, just like other JIT compilers do.
Re:Racket: The Lisp for the Modern Day by criddell on Thursday June 29, 2023 @10:32AM (#36520871)
Oh okay. I was thinking of self-modifying, not just code generation. That was something that was done occasionally by DOS and Windows programmers before the introduction of DEP in Windows XP.
Re:Racket: The Lisp for the Modern Day by trws on Thursday June 29, 2023 @11:36AM (#36521900)
Yeah, self modifying has become harder. As far as I know the most robust solution to that now is like what Julia does, where it can compile new generations of any module to update call targets, for example. At worst, when seccomp disallows flipping a writable page to executable at runtime, you can always compile into a file then dlopen the file. In other words, it can take many more contortions now than it used to, but it’s still possible.
Re:Racket: The Lisp for the Modern Day by dorfsmay on Thursday June 29, 2023 @10:12AM (#36520601)
Was lisp compiled code, not code.running in a repl, ever able to self modify?

It looks like that wasn't the case even in 1996:

https://groups.google.com/g/comp.lang.lisp/c/O1dDXlQsVkw

Re:Racket: The Lisp for the Modern Day by pfdietz on Thursday June 29, 2023 @01:13PM (#36523390)
One can define and compile functions in a running Common Lisp. There's a standard function, compile, that does this.

In SBCL, any evaluation of an expression is done by first compiling it.

Re:Racket: The Lisp for the Modern Day by dreamcompiler on Thursday June 29, 2023 @03:00PM (#36525162)
Self modifying code in the sense of changing one instruction to another at runtime (as was commonly done in assembler in the 1960s) is not generally possible with modern Common Lisps mostly because modern operating systems don't allow it. And that's a good thing because such code would be hopelessly insecure and impossible to reason about.

But if you mean "compile a new function called X and replace the old X at runtime", that's easy in Common Lisp. It's not commonly done unless you're explicitly writing some kind of compiler.

What is commonly done is to create a lexical closure at compile time and change its bound values at runtime. IOW changing the private data of a function at runtime is more generally useful than changing its instructions.

What's most common is to write lisp programs that emit lisp source code and compile it at compile time (but usually not run time). Such programs are called macros.

Re:Racket: The Lisp for the Modern Day by perihelions on Thursday June 29, 2023 @11:00AM (#36521317)
I just checked: SBCL on Linux/amd64 puts compiled functions in a r+w+x page. You could write Lisp that writes Lisp that writes self-modifying machine code, and it would (I think) run by default.

    (compiled-function-p #'f) ; T
    
    (disassemble 'f)
    ; disassembly for F
    ; Size: 58 bytes. Origin: #x5350CD14                          ; F
    ; 14:       498B4510         MOV RAX, [R13+16]                ; thread.binding-stack-pointer
    ; 18:       488945F8         MOV [RBP-8], RAX
    ; 1C:       4883EC10         SUB RSP, 16
    ; [...]


    $ pmap $PID --range 5350CD14
    442331:   /usr/bin/sbcl
    0000000053498000 122272K rwx--   [ anon ]
     total           122272K
Re:Racket: The Lisp for the Modern Day by waffletower on Thursday June 29, 2023 @11:08AM (#36521426)
No, 'eval' is available in many dynamic languages and needs to be utilized with care
Re:Racket: The Lisp for the Modern Day by mark_l_watson on Thursday June 29, 2023 @10:47AM (#36521113)
I agree, Common Lisp is crufty but really stands the test of time. I have been using Common Lisp since about 1982 and old code still runs fine.

My relative use of Lisp languages: Common Lisp 60%, Racket 20%, Haskell 5%, Clojure 5%, and various other Schemes 10%. Unfortunately since most of my work in the last 8 years has been deep learning, LLMs, LLM chains, etc., I spend a little over half my time now using Python. So it goes...

Re:Racket: The Lisp for the Modern Day by i_am_a_peasant on Thursday June 29, 2023 @11:53AM (#36522152)
That Vonnegut reference at the end ;D
Re:Racket: The Lisp for the Modern Day by deckard1 on Thursday June 29, 2023 @02:57PM (#36525113)
"old code runs fine" is a poor benchmark for how well a language holds up over time. All x86 code still runs fine. Perl 5 is from, I think, 1994. It's still maintained and in development. Most C code from the '80s would still compile and run just fine (at least POSIX-based, Windows however...). You can trivially find Pascal, Fortran, COBOL, and Forth code that all "still runs fine."

I don't think it's a particularly unique or interesting quality, that some old code still runs. After all, I can go to archive.org right now and run all of that ancient DOS, Amiga, whatever code in a 100% exact (or close to) emulator in my browser.

Re:Racket: The Lisp for the Modern Day by waffletower on Thursday June 29, 2023 @11:01AM (#36521336)
I am curious how performant compiled Common Lisp is compared to GraalVM compiled Clojure native images. You certainly don't give up macros and code generation when using Clojure, though you do give up a specific class of explicit reader macros. Some reader extensibility can be had (and is used in Clojure.core) via reader functions (data_readers.clj)
Re:Racket: The Lisp for the Modern Day by pfdietz on Thursday June 29, 2023 @01:10PM (#36523337)
You don't give macros and code generation when using compiled Common Lisp, either.