8 ms·
X server in 5000 lines of Common Lisp
- apetresc 13y agoOne of the prerequisites for using this is, apparently, an already-running X server.
- stmartin 13y agoHAHAHAHHA :)
- dman 13y agoCan this restriction be removed using EGL ?
- pyb 13y agoIn principle yes
- e12e 13y agoWell, the natural thing to do is compile the lisp to javascript and use webgl! Would be interesting to see how much is needed to get it running with some other gl context. Also -- maybe this'll run under OS X and windows without requiring a X server for the GL context?
- bane 13y agoSo by implementing none of the hard bits, LISP wins again!
- dman 13y agoLisp featured support for Garbage collection, exceptions done right, macros, optional typing, native compilation. In fact I would argue that many in the lisp community were so obsessed with the hard bits that they overlooked building simple things that see everyday use in the real world.
- lispm 13y agoQuite some bits were implemented in Lisp. Both simple and hard. Some of the bits are lost. For example the TI Explorer Lisp Machine came with an X11 server written in Lisp. On my Symbolics Lisp Machine I used the usual MIT X11 server written in C - this was possible because the Symbolics Lisp machine had a C compiler.
- gcr 13y agoI was under the impression that those machines evaluate Lisp forms at the hardware. How could a C compiler work? Does it translate your code into Lisp s-expressions, or is there like a bytecode layer in between?
- pyb 13y agoThis is an instance of a C to Lisp compiler that translates to s-expressions https://github.com/vsedach/Vacietis https://github.com/vsedach/Vacietis
- xenophonf 13y agoWhat do you think a compiler does? The target instruction set can be any Turing-complete language. Compiling C to LISP is no different than compiling LISP to C (e.g., GNU Common Lisp), compiling ML to Java (which is so easy students can do it in 300/400-level CS), and so on.
- stormcrowsx 13y agoYou make it sound of easy. How hard is it to go from a GC language to a non-GC language? What methods do you use to fill in GC?
- groby_b 13y agoIt's the runtime environment that provides that. And GC's for C are pretty easy to come by :)
- 13y ago
- juliangoldsmith 13y agoIt's not that it doesn't implement the hard bits, it just re-implements the hard bits on top of the hard bits. It requires an OpenGL context, which generally requires you to have an X server running.
- pubby 13y agoIt should have been written using lazy evaluation. That way, it could use itself recursively as its own X server. /sarcasm
- jfoutz 13y agoI think Haskell has the market cornered on tying the knot. http://www.haskell.org/haskellwiki/Tying_the_Knot http://www.haskell.org/haskellwiki/Tying_the_Knot
- hga 13y agoWell, according to the Readme, it's a "decent OpenGL driver" which then means "unfortunately, a running X server :) (to create a GLX context)"
- aidenn0 13y agoApparently this is 3 years old.
- ritchiea 13y agoCool though it's going to be egg on OP's face when someone else implements this in 12 lines of Javascript
- 10098 13y agoWait, you need an X server to run it? What's the point then?
- _delirium 13y agoIt looks like it just uses an existing X server as a way to create an OpenGL context, not as an X server per se. Perhaps it would be possible to port it to some non-X method of producing an OpenGL context, such as EGL.
- dmytrish 13y agoBecause this glosses over the really complex parts. Still, if they are written in Lisp, this would comprise a complete self-sufficient X server (how many lines of code this would take though?).
- elwell 13y agoIsn't Lisp really hard to understand? Or is it just because I'm unfamiliar with the syntax?
- S4M 13y agoI guess it's you who is just unfamiliar with the syntax. Do you find (+ 2 2) harder to understand that 2+2? If the code is well indented, IMHO it's quite understandable. For example, what do you think of this Lisp code snippet (it's not the best possible code, just some stuff I have at hand to show without you needing to know the context): ;;takes two list l1 and l2 of same length, and return (l1[0] l2[0] ;;l1[1] l2[1] ...) (defun mix (l1 l2) (if (null l1) nil (append (mix (cdr l1) (cdr l2)) (list (car l1) (car l2))))) EDIT: formatted the code as per gcr suggestion.
- gcr 13y agoIn HN, use four spaces to indent code blocks, like this: ;;takes two list l1 and l2 of same length, and return (l1[0] l2[0] ;;l1[1] l2[1] ...) (defun mix (l1 l2) (if (null l1) nil (append (mix (cdr l1) (cdr l2)) (list (car l1) (car l2))))) (Also, for the record, you should say (append (list ...) (mix ...)) or else you'll reverse the result list, which I don't think is your intent)
- S4M 13y agoThanks for the tip of the indentation, and for checking my code - you are right that I got the order wrong in (append (mix ...) (list ...)), but in this particular case I'm not interested in how my list is ordered.
- e12e 13y agoThis shows off one of lisp's (INHO) unfortunate anachronisms, namely that your "other car is first". CDR and CAR refer to machine instructions on the IBM-704 that had a (by today's standards) a somewhat quaint handling of "words" in memory, roughly allowing CAR to refer to a data element at the head of a linked list, and CDR to refer to the pointer to the rest of the list (or the empty list) (As well as a CONS instruction to build a word in memory from for parts, including the two 15 bit values that CAR/CDR refer to)[1]. Lisp then extended this by allowing programmers to combine c(a|d)+r, to get the equivalent of second, third, first-of-second-sublist etc. I'm not convinced the succinctness is worth it -- apparently experienced lisp-coders disagree. The TL;DR is that if you don't know lisp, this code is the same as the above, and is a bit more intuitive: ;;takes two list l1 and l2 of same length, and return (l1[0] l2[0] ;;l1[1] l2[1] ...) (defun mix (list1 list2) (if (null list1) nil (append (mix (rest list1) (rest list2)) (list (first list1) (first list2))))) Other languages might use head and tail, rather than first and rest. I'll agree that list1 and list2 might not offer much more readability than l1 and l2 -- at least not with the comments given. [1] Most of this is paraphrased from wikipedia, and what I remember from various times I've tried to get started with lisp, without ever really getting entirely comfortable with the language. http://en.wikipedia.org/wiki/CAR_and_CDR http://en.wikipedia.org/wiki/CAR_and_CDR [edit: I didn't notice the comment about reversing the list, but I think it is rather obvious that (append rest list(first)) does indeed reverse the order...? I actually wondered if append had a strange order of parameters while I "rewrote" the code :-) ]
- daemonize 13y agoGood luck groking that mess.
- gcr 13y agoIt's hard to grok low-level code like this in any language. I'd take common lisp over heavily-templated C++ or freestyle Perl any day.
- koenigdavidmj 13y agoBanging on file descriptors looks pretty much the same no matter what language you do it in. I expect that a Python equivalent would be pretty much the same length.
- pyb 13y agoI actually left this project alone after I got the very basics running... It's very very slow and rather buggy. I guess a profiling run could help a lot though.
- sytelus 13y agoTo me 5000 lines of C code is a LOT of code. Linus's first release of Linux was only 10,000 lines of code. Given much higher expressiveness of Lisp, I think 5000 lines of List code is not all that to boast about. I can't pull a reference here but according to one of the studies, the productivity of some of the well known programmers was measured at 10K LOC/year (yes, it's very loose measure of "productivity"). So writing 5000 lines of good code may require ~6 months, i.e., not a trivial amount of work. Although I agree it is cool to have X server in Lisp.
- varjag 13y ago5000 lines isn't really a lot for a real-life project in any language. Besides, a lot of the code here seems to be in the data. E.g. https://github.com/pyb/zen/blob/master/data/request-specs.lisp https://github.com/pyb/zen/blob/master/data/request-specs.li... describes X spec request syntax, accounts alone for nearly 1000 lines, and it's not really possible to trim down.
- dmytrish 13y agoAgreed, I was surprised how many code Slime implementation has, there are source files about several kloc in size. From what I saw I can say that "lisp expressiveness" did not helped much there.
- qbrass 13y agoHere's Xorg's nested X server if you want to see how much C code it takes. http://cgit.freedesktop.org/xorg/xserver/tree/hw/kdrive/ephyr http://cgit.freedesktop.org/xorg/xserver/tree/hw/kdrive/ephy...