Slashdot Mirror


How Would You Generate C Code Using Common Lisp Macros? (github.com)

Long-time Slashdot reader kruhft brings news about a new S-Expression based language transpiler that has the feel of C. This structure allows for the creation of code generation macros using the full power of the host Common Lisp environment, a language designed for operating on S-Expressions, also known as Lists. It is unknown exactly what power might come about from this combination of low level processing with high level code generation.
This has prompted some discussion online about other attempts to convert Lisp to C -- raising several more questions. How (and why) would you convert your Lisp code into C, and what would then be the best uses for this capability?

108 comments

  1. I remember when I was young... by Anonymous Coward · · Score: 1

    ... and had time to waste on idle thoughts.

  2. Why give Chris a lisp? by Anonymous Coward · · Score: 0

    It's already hard enough to clearly understand.

    1. Re:Why give Chris a lisp? by Anonymous Coward · · Score: 0

      thath's stho not funny.

  3. Butterflies by rsilvergun · · Score: 3, Funny

    Oblig XKCD

    --
    Hi! I make Firefox Plug-ins. Check 'em out @ https://addons.mozilla.org/en-US/firefox/addon/youtube-mp3-podcaster/
    1. Re:Butterflies by K.+S.+Kyosuke · · Score: 4, Funny

      To honor Carrie Fisher, you should have posted this.

      --
      Ezekiel 23:20
    2. Re:Butterflies by No+Longer+an+AC · · Score: 1

      Dunno why this was modded troll. At worst it's not very funny, but it is somewhat relevant.

      I learned LISP once. I think I used emacs at the time too.

      My first and only thought upon seeing this headline was "Why would you do that?"

      But I've been told over and over again that LISP is a great language and you can....do things in it....artificially intelligent things even. LISP was kind of considered cool when I was in college, but I was instead swept up by the practicality and usefulness of C - and I switched to vi as well.

    3. Re:Butterflies by K.+S.+Kyosuke · · Score: 1

      the practicality and usefulness of C

      Such as the lack of generic arithmetics and type checking of heterogeneous data or the presence or pervasive manual memory management and error handling? ;)

      --
      Ezekiel 23:20
    4. Re: Butterflies by bsDaemon · · Score: 4, Funny

      No, that would be this one:
      https://xkcd.com/224/

    5. Re:Butterflies by Anonymous Coward · · Score: 1

      You... say that like it's a bad thing?

    6. Re:Butterflies by K.+S.+Kyosuke · · Score: 1

      Well, manual register allocation and data shuffling in assembly apparently was. Now we have optimal allocators and nobody's bothered with it anymore. Software capabilities do improve...

      --
      Ezekiel 23:20
  4. I wouldn't by Anonymous Coward · · Score: 2, Insightful

    What kind of dumb article is this? Stop living in the past Grandpa.

    1. Re:I wouldn't by Anonymous Coward · · Score: 2, Insightful

      Stop chasing the fad of the moment and learn to actually hone a mature skill set, son.

    2. Re:I wouldn't by Anonymous Coward · · Score: 0

      you can keep your javascript constructed hell..

    3. Re:I wouldn't by ShanghaiBill · · Score: 2

      you can keep your javascript constructed hell..

      Javascript is actually used in the real world.
      Lisp is not.
      And Lisp had a 40 year head start.

      Javascript is far from perfect, but at least I can look at code written by someone else, and understand it.
      That can't be done with Lisp.

      Did you look at the code samples in TFA?
      What possible real-world application could there be for that gibberish?
      If The Onion published tech articles, I would assume this was a joke.

    4. Re:I wouldn't by hey! · · Score: 2

      I would argue that Javascript until fairly recently was barely used in the real world. As someone who learned to program at MIT in the early 80s, Javascript feels a lot like Scheme -- a dialect of Lisp. But until Node came along people were using it like Visual Basic.

      As for Lisp in the real world, it definitely *is* used, but largely for things companies like to keep close to their vests -- defense, finance, that kind of thing. You can search for lisp jobs -- there are plenty out there, but they're not code monkey positions.

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    5. Re: I wouldn't by Anonymous Coward · · Score: 0

      I'm a woman you sexist pig!!!

    6. Re:I wouldn't by Anonymous Coward · · Score: 0

      at least I can look at code written by someone else, and understand it.
      That can't be done with Lisp.

      Heh, It's gonna be hard for me to forget this moment the next time you start off on another self-righteous rant.
      That time ShanghaiBill admitted he can't understand lisp, the language with the least syntax and closest to human language of any programming language.

      It's ok, you aren't the only institutionalized idiot.

    7. Re:I wouldn't by John+Allsup · · Score: 1

      Interestingly, Javascript's heritage is from Self, which descends from Smalltalk, and dispenses with classes.

      --
      John_Chalisque
    8. Re: I wouldn't by Anonymous Coward · · Score: 0

      there are no women on the internet, sorry son!

    9. Re:I wouldn't by K.+S.+Kyosuke · · Score: 1

      As someone who learned to program at MIT in the early 80s, Javascript feels a lot like Scheme -- a dialect of Lisp.

      That's because it was initially supposed to be Scheme, before some fashion-conscious suits ordered Eich to turn it into something that looks like Java.

      --
      Ezekiel 23:20
    10. Re:I wouldn't by K.+S.+Kyosuke · · Score: 1

      Javascript is far from perfect, but at least I can look at code written by someone else, and understand it. That can't be done with Lisp.

      Fortunately, the statement in question included "I" instead of "one", otherwise Lisp would be doomed!

      --
      Ezekiel 23:20
    11. Re:I wouldn't by TheRaven64 · · Score: 1

      And Smalltalk was heavily inspired by Lisp.

      --
      I am TheRaven on Soylent News
    12. Re:I wouldn't by Anonymous Coward · · Score: 0

      CommonLisp is used a lot in the real world.

    13. Re:I wouldn't by hey! · · Score: 1

      If you go back far enough you have a choice of Lisp or COBOL for inspiration.

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    14. Re:I wouldn't by rochrist · · Score: 1

      Don't forget SNOBOL!

  5. hmm by Billly+Gates · · Score: 1

    Sounds like an emacs junky trying to validate why his editor is the be all end all. Can atom.io or vi create c automatically? Well mine can

    1. Re:hmm by phantomfive · · Score: 1

      Theoretically, I can see it as a nice way to interact with C libraries.

      --
      "First they came for the slanderers and i said nothing."
    2. Re:hmm by ogdenk · · Score: 1

      What the hell does this have to do with Emacs? This is about Common Lisp, a real language.... not the crippled Emacs Lisp.

  6. Re: Why give C a lisp? by Anonymous Coward · · Score: 0

    Spell check probably couldn't understand my lisp....

  7. My favorite by jwymanm · · Score: 1

    Still my favorite syntax for programming and I believe will always be. I mostly use Clojure at the moment but definitely wanted something just like this to work closer to C.

    1. Re:My favorite by Anonymous Coward · · Score: 0

      The best part about the syntax is that there's basically none. I hate that Lisps went "out of style" in the 80s with the death of .gov/.mil AI research, but I'm hoping for a resurgence. Clojure is neat, but I'd still prefer good old Common Lisp.

  8. Excellent by phantomfive · · Score: 4, Funny

    All the beauty of C syntax with all the conciseness of Lisp:

    (int main ((int argc) (char (** argv)))
         (sswitch ([] argv 1)
              (case ("a" "c")
            (printf "The value is \"a\" or \"c\"\n"))
              (case "d"
            (goto e-label))
              (case "b"
            (printf "The value is \"b\"\n"))
              (case "e"
            (: e-label)
            (printf "The value is \"d\" or \"e\"\n"))
              (default
              (printf "The value is neither \"a\", \"b\", \"c\", \"d\", or \"e\"\n")))
         (return 0))

    --
    "First they came for the slanderers and i said nothing."
    1. Re:Excellent by dgatwood · · Score: 5, Funny

      I'm suddenly reminded of the Russian spy who tried to steal the source code for the American missile defense system. When he got home, he discovered that he had nothing but three pages filled with close parentheses. "The bad news," the spy said, "is that we only got the last three pages, and they contain no useful code. The good news is that we now know what language it was written in."

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    2. Re: Excellent by kruhft · · Score: 1

      Yeah, but being able to do a switch on strings is pretty cool, is it not?

    3. Re: Excellent by Rockoon · · Score: 1

      QuickBasic wants its argument back.

      --
      "His name was James Damore."
    4. Re: Excellent by Anonymous Coward · · Score: 1

      Not really that cool, it's been possible to do that since the 70s. Hint: a string constant is just a pointer to a unique memory location. You can cast the first two bytes as an integer, then the switch works on strings for all intents and purposes.

    5. Re: Excellent by Raenex · · Score: 1

      Sounds like the kind of non-portable hacks C is infamous for.

    6. Re: Excellent by Anonymous Coward · · Score: 0

      That doesn't work if the strings to compare aren't constants or if they're defined in different modules or if the stars don't align for some different reason.
      Unlike in some other languages, there's no guarantee in C that two identical strings must be the same object, nor that in switches the contents of strings will be compared.
      So a constant string "Hello" defined in myprogram.exe will be different from a constant string "Hello" defined in mylibrary.dll and also different from a string "Hello" that the user entered in a text box.

    7. Re: Excellent by phantomfive · · Score: 1

      Unlike in some other languages, there's no guarantee in C that two identical strings must be the same object,

      I don't think that's true in any language.

      --
      "First they came for the slanderers and i said nothing."
    8. Re: Excellent by Anonymous Coward · · Score: 0

      In fact, there is string interning functionality in many many LISPs and it IS guaranteed that two equal interned strings are the same object. It drives me up a wall every time I have to use C++ or something where that's not the case. I have to let it compare the token by comparing character by character? What?

    9. Re: Excellent by Anonymous Coward · · Score: 0

      I wouldn't say that C in infamous for it. You can certainly do things like that but even the most experienced programmer knows that it is an ugly unportable hack.
      As for portability, properly written C is actually portable unlike most high level languages out there.
      Languages that are portable between Windows/Mac/Linux/BSD are a dime a dozen. You can pick almost anything.
      If you want to write programs that have actual portability there aren't that many alternatives to C.
      If you ditch the low end platforms you might be able to get python running on it.

      Of course you can place everything in a virtual machine and call it portable as long as you can get the virtual machine running. That gives you about the same limits as the python case.
      If you can live within the NES virtual machine it probably exists for a couple of more systems than the high level languages that boasts portability.
      Of course that means that you'll end up programming 6502 assembly or C anyway.

    10. Re: Excellent by Anonymous Coward · · Score: 0

      No. you don't do that in any language.
      Even in pure ISO-C you call the string comparison method, just like the high level language does without telling you.
      The big difference is that C makes it obvious to you if you are making a comparison between the string content or the string references.
      Not all high level languages allows you to check that.
      Heck, some higher languages might even decide that one of your string is of the wrong type for comparison and reallocate it on the fly.
      It's all very convenient if you don't care about knowing if your code could cause an exception there in low memory cases.

    11. Re: Excellent by Raenex · · Score: 1

      I wouldn't say that C in infamous for it.

      I would. The mess around pointers, types, and casting, and what is portable and what isn't, along with clever C hacks abounds.

      You can certainly do things like that but even the most experienced programmer knows that it is an ugly unportable hack.

      Which is why somebody recommended it and it got upmodded.

      As for portability, properly written C is actually portable unlike most high level languages out there.

      Well, sure, if you believe in the myth that we just need to have more education, hire better C coders, or strive to do better, C is a good choice for a "portable" language. But in reality C has inherent design flaws that make it easy to write non-portable code.

      If you want to write programs that have actual portability there aren't that many alternatives to C.

      That's because C has inertia and everybody ports it to their platforms. It's the king of worse is better.

    12. Re:Excellent by syntotic · · Score: 1

      It looks ambiguous.

    13. Re: Excellent by david_thornley · · Score: 1

      A lot of C code will fail in low-memory situations. If the program doesn't test every return from malloc() or calloc(), it will potentially do operations on the null pointer. As long as you stay out of embedded software, a low memory situation is probably from the process using all available memory, and the question is not whether it will fail but when.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  9. I don't know about you by 93+Escort+Wagon · · Score: 1

    But, upon reading the summary, I shuddered - I felt a chill as if Satan himself had walked across my grave...

    --
    #DeleteChrome
    1. Re:I don't know about you by Anonymous Coward · · Score: 3, Funny

      Who's providing internet access to your grave?

    2. Re:I don't know about you by plopez · · Score: 1

      Yeah another IoT security breach.

      --
      putting the 'B' in LGBTQ+
  10. Code as structured data, and pre-parsed source by John+Allsup · · Score: 1

    It is not the best illustration of an idea that's been running around my head for ages.

    In terms of what traditional textual C can represent, with the exception of C macros, one can construct a suitable data structure. Now consider how parsed C could then be programmatically manipulated, and produced from other source formats than the usual. And so on.

    Thinking more in a pythonic syntax, I have wondered about replacing textual source with a scripting language, so that, with something like C++, we could write

    newclass = cpp.Class()
    meth = newclass.addMethod(name="dosomething")
    meth.signature = cpp.Signature([cpp.int,cpp.float])

    While it doesn't look pretty at this point, one can write routines which do much of the code generation for you. Sometimes I look at the clever stuff done with template metaprogramming and think that they are doing this sort of thing but with a hobbled language. (cf. Greenspun's 10th law)

    This has the capacity to do far more than C macros, and to allow a programmer to see in detail what things like macros and templates turn into.
    An IDE could interactively work with the resulting data structure, avoiding the round-trip to textual source and back,
    and the compilation stage for large projects could be accelerated in various ways.

    Basically, in Lisp, code is structured data, as is essentially everything else, and essentially you are working with the language downstream from the parser (or at least, you could easily construct and editor which did this, and where a textual representation was only constructed by the tools allowing you to view and edit the programs. With other languages, code is a text file that needs parsing.

    --
    John_Chalisque
    1. Re:Code as structured data, and pre-parsed source by serviscope_minor · · Score: 1

      Have you looked at rust and d?

      --
      SJW n. One who posts facts.
    2. Re:Code as structured data, and pre-parsed source by kruhft · · Score: 1

      newclass = cpp.Class()
      meth = newclass.addMethod(name="dosomething")
      meth.signature = cpp.Signature([cpp.int,cpp.float])

      Interesting idea and I like where it could go. Thank you.

    3. Re: Code as structured data, and pre-parsed source by Anonymous Coward · · Score: 0

      Congrats, on your way reinventing ruby. It's not too practical or performant though very very productive. Prefer golang now.

    4. Re:Code as structured data, and pre-parsed source by TheRaven64 · · Score: 1

      newclass = cpp.Class()
      meth = newclass.addMethod(name="dosomething")
      meth.signature = cpp.Signature([cpp.int,cpp.float])

      Welcome to 1976. This is exactly how Smalltalk works. Unlike later class-based languages, it's a purely imperative system: you create a new class by sending a subclass: message to a class, with the name of the new class as the argument. The return value is the new subclass. You then add instance variables and methods to the class in a similar way.

      --
      I am TheRaven on Soylent News
    5. Re:Code as structured data, and pre-parsed source by rkww · · Score: 1

      I have wondered about replacing textual source with a scripting language

      You're pretty much describing ici

  11. Asking Obvious by Anonymous Coward · · Score: 0

    You already know why. When your C-compiler produces better code for the performance dependent parts of the system than the LISP compiler in your particular system for your particular LISP application, you'll have the option of transpiling. In other words, it depends.

    1. Re:Asking Obvious by kruhft · · Score: 1

      Unfortunately, the editors messed up a bit with the explanation of what sxc is and what it is good for. It's not about compiling your Lisp code to C, it's about writing C code using Lisp. With the S-Expression syntax of sxc, a whole world of macro programming and code generation become possible in a natural matter leading from the using of S-Expression and macros. This, so far, has been uncharted territory, although his type of project is quite popular to implement. It seems that nobody has actually used to it's full potential yet; hence the question.

      What do you think that the combination of a high level language for the generation of a low level processing language would provide, if anything over the normal combinations of cc + cpp?

    2. Re:Asking Obvious by jellomizer · · Score: 1

      The performance of C or any low level language is up to the ability of the programmer and the deadlines placed on them, or the fact they may get board or wiring that one section and say good enough. The reason why most software sucks and every developer thinks they can do x, y or z better is probably because they can with some time. However most people don't have the time to just sit there and fix every part until it reaches optimal because they could waste their life away on a piece of code that may not be worth the life's effort.
      Higher level languages often take the burden from us and give us a presets of better than good enough tools to work with.
      So when I say x.sort() I am confident that it isn't a lazy bubble sort where I needed to code in the last minute because the product was due the next day and x will only be a small list currently and the testers won't see a problem. Until 3 years later after a spec change caused that small list to be huge and slowed the system down.

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    3. Re:Asking Obvious by Anonymous Coward · · Score: 0

      What do you think that the combination of a high level language for the generation of a low level processing language would provide, if anything over the normal combinations of cc + cpp?

      Refactoring that works? ;) Aspect oriented programming would be an interesting experiment for such a combination. At least enforcing coding standards should be easy, as well as generating code for a standard such as MISRA.

  12. Use unparser by Frans+Faase · · Score: 1

    I would let LISP print out a s-expression representing the abstract syntax tree (usually called abstract parse tree). Next I would add a small piece of code to my IParse program to read s-expression and use the unparse abilities with the C grammar to produce nicely formatted C code. The unparse function is smart enough to output a S-expression like '(times (add 3 4) 5) into (3+4)*5 based on the given grammar rules fed to IParse. Feel free to contact me, if you want any help with using IParse.

  13. More Machine Generated C Code by Anonymous Coward · · Score: 0

    Who would think there could ever be enough of that loose in the wild!

  14. There is only one answer by BlindRobin · · Score: 1

    With great trepidation and a bottle of aquavit, and the obvious subconscious yearning for discipline ultimately resulting in years of medication augmented therapy.

    1. Re:There is only one answer by Anonymous Coward · · Score: 0

      aquavit. I love it but how many people will recognize the term.

    2. Re:There is only one answer by plopez · · Score: 1

      The beverage or the lab chemical (though one can be both but not the other)?

      --
      putting the 'B' in LGBTQ+
  15. How? by Gravis+Zero · · Score: 3, Funny

    Weeping and at gunpoint. ;)

    --
    Anons need not reply. Questions end with a question mark.
  16. I wouldn't by wonkey_monkey · · Score: 1

    I wouldn't, because I'm not a masochist. Next question.

    --
    systemd is Roko's Basilisk.
  17. Lisp to C by jbolden · · Score: 3, Interesting

    How (and why) would you convert your Lisp code into C

    Well that's pretty easy. There are tons of simple Lisp compilers. Heck building a LISP used to be an exercise for many years included (full source) with Microsoft's C compiler.

    A few examples:
    http://www.buildyourownlisp.co...
    http://howtowriteaprogram.blog...
    http://sbcl.sourceforge.net/
    http://clisp.sourceforge.net/

      A little off topic but a Lisp in Java by a master of the programming craft which is worth looking at: http://norvig.com/jscheme.html
    And finally also off topic but the original LISP in assembly: http://www.softwarepreservatio...

    In short the way you convert LISP to C is writing a LISP interpreter or compiler.

    1. Re:Lisp to C by Anonymous Coward · · Score: 0

      Exactly. I see lisp to C, I think "Oh good. Maybe they'll finish this time so I can actually compile LISP for any oddball platform."

    2. Re:Lisp to C by K.+S.+Kyosuke · · Score: 1

      If one is interested primarily in code generation, there's a very nice formatter for Scheme (think printf on steroids) written by Alex Shinn that has extensions for generating C-ish output.

      --
      Ezekiel 23:20
    3. Re:Lisp to C by K.+S.+Kyosuke · · Score: 1

      I suppose you can, with Gambit-C. It's pretty much the best lisp-to-C option, modulo the absence of modules (hah!). Some people wrote module systems for it, though.

      --
      Ezekiel 23:20
    4. Re:Lisp to C by tgv · · Score: 1

      True. I wrote toy one 20 years ago with the assumption you wouldn't make circular data structures and it was pretty fast. You couldn't do things like (set (f ...) (g ...)) either, of course. But I couldn't and can't find good use for Lisp-to-C. There are good compilers out there, so why bother going via C?

    5. Re:Lisp to C by jbolden · · Score: 1

      I think the way you generally handle something like this is through void pointers. Part of the data structure becomes a void function pointer. That's perfectly legal in C. You just have to be careful that when you set out to run a step in the evaluation you have all your types in line.

  18. Why? Just why? by Anonymous Coward · · Score: 0

    Who bothers with Lisp? Only twisted people used it to begin with.

  19. Lipth wifout macros failed by Anonymous Coward · · Score: 0

    I twfied to write she code wif a plain old wipth but it didn'th work outh so well.

    #include "<stdio.h>"
    inth main(inth argshe; char **)
    {
    pwintf("Hello word\n");
    }

    I kepth getting compiwer ewos.

    Maybe a macwo would help.

  20. Not by Anonymous Coward · · Score: 0

    aight, cya

  21. Re:Why? Just why? by RightwingNutjob · · Score: 2

    Yes and no. Yes in that functional programming isn't nearly all it's cracked up to be by its evangelists. No in that there are some applications (mainly in things involving control systems, physics modelling, and a few other niche applications) where Lisp is a much more elegant (read: less spaghetti-prone) way of writing the code, and having a good way to make your academic Lisp usable in real software is a way to make your life easier if you happen to work in one of those domains.

  22. C ... by CaptainDork · · Score: 1

    ... arefully.

    --
    It little behooves the best of us to comment on the rest of us.
  23. Kyoto Common Lisp by ooloorie · · Score: 2

    Kyoto Common Lisp and its descendants compile into C.

  24. MRD Required. by Hylandr · · Score: 1

    Can you describe the business requirement behind the ask please?

    --
    ~ People that think they are better than anyone else for any reason are the cause of all the strife in the world.
  25. Back to the future by rlk · · Score: 1

    We had a genuine Lisp->C transpiler (we just called it a converter) way, way back when (in the late 1980's, probably before a lot of you were born and maybe even in some cases before your parents were born) at Thinking Machines Corp. The system software for the Connection Machine CM-1/CM-2 (which was effectively a gigantic coprocessor) was originally written in Lisp for the Lisp Machine (Symbolics 36xx IIRC), but eventually we figured out that we needed it on *ahem* more conventional platforms. Rather than rewriting all the code, someone hacked together a Lisp->C converter.

    1. Re:Back to the future by kruhft · · Score: 1

      Thank you for your anecdote, I appreciate the comparison with on of my favourite supercomputer companies! sxc is not necessarily a 'Lisp to C' converter, but a C -> C converter with the optional metaprogramming facilities to generate code using Common Lisp. The syntax of the sxc language is Lisp like; the semantics are C. So really this is a C -> C translator with added meta facilities.

      The code that goes in and the code that comes out is strictly C. What you can do with the added ability of Common Lisp is really what's at question for me.

  26. Facebook by darkain · · Score: 2

    Facebook already did this with PHP. It was called HipHop. But it sucked. Too many issues, and it didnt solve enough issues. Luckily, Facebook started over from scratch, and just built of PHP virtual machine that does JIT compilation instead of needing to compile PHP into C then into machine language, and the result is actually a faster product, which supports more of the PHP language, and is a hell of a lot more stable (still not perfect though)

    So, why bother cross-compiling to another language? Just build a LISP JIT VM system. Solve all your problems! :D

    1. Re:Facebook by kruhft · · Score: 2

      Unfortunately the editors made a slight mistake with the description of this tool. It's not to 're-write your lisp code in C', it's to write new C code using Lisp as the macro system.

      HipHop was interesting in that it would compile PHP and make it run faster, but it's not similar to this in any way.

      sxc is a dialect of Lisp that has the semantics of C. There's not cross compilation from anything to anything; the syntax of sxc is that of C, but you're editing a representation of the parse tree. This is a list, and the meta-programming facilities allow you to generate code using Common Lisp, the most powerful language for generating that type of data structure; the list.

      The homoiconicity that this provides to C gives me suspect to say that it is a more powerful language overall than cc + cpp.

    2. Re:Facebook by Anonymous Coward · · Score: 0

      In the thing I am using building, lots of functions can only happen if code is generated during run time, which is provided by a LISP like language; the hard parts run as alternate C++ compiled processes. What this people mean would obviate the child processes and embed either one language into the other one, though as it goes for the concomitant C++ compiled processes it can leverage on multiprocessor and wire protocols and OS support. I would rather place a JIT C++ compiler than do it the other way around, though I am not quite sure C++ can be jitted.

  27. Re:Why? Just why? by Anonymous Coward · · Score: 0

    mainly in things involving control systems, physics modelling

    Those were almost the last places I would have expected to find preference to functional approach due to modelling with state machines and vectorization of code for any vector units available.

  28. Not gonna do your homework by Anonymous Coward · · Score: 0

    I'm not going to do your Senior Project for you.

    1. Re:Not gonna do your homework by kruhft · · Score: 2

      It's not a senior project; I graduated 20 years ago[1]. It's a tool I've created recently from some ideas I've seen and had in hopes of realizing something that is more than the sum of it's parts.

      [1] Here's my senior project: http://github.com/burtonsamogr... ;-)

  29. Editing changed the question, unfortunately by kruhft · · Score: 2

    I'm glad this story got posted and sxc is getting some press, but the real question I asked was:

    It is unknown exactly what power might come about from this combination of low level processing with high level code generation. Can you think of any possible uses?

    The idea of using pre-processors to generate C code is not new to programming; but the usage of the full power of Common Lisp in such a natural way is up to the question.

    1. Re:Editing changed the question, unfortunately by K.+S.+Kyosuke · · Score: 2

      Can you think of any possible uses?

      Yes. Formulate a performance-sensitive problem (such as FFT, or linear algebra, or some other numerical problem, but even stream processing or other data reduction might be interesting areas) in a high-level form, then translate it non-deterministically (and perhaps also parametrically) using for example tree-pattern-matching replacement into a low-level form, say, in C (but low-level Lisp works, too). Do this a few million times and benchmark the results. You may have found a faster solution to your original problem than what you might be able to write on your own with a substantial time investment.

      --
      Ezekiel 23:20
    2. Re:Editing changed the question, unfortunately by hcs_$reboot · · Score: 1

      Btw shouldn't this article be in the "Ask slashdot" category since it comes from a reader, and not from some news..

      --
      Slashdot, fix the reply notifications... You won't get away with it...
    3. Re:Editing changed the question, unfortunately by kruhft · · Score: 1

      Thank you for the interesting response. Could you explain a bit more about what you mean by "using for example tree-pattern-matching replacement into a low-level form". What would you be replacing with what?

      My goto performance sensitive problem has always been raytracing, so I think that's the next logical project to implement with this tool and see where it goes.

    4. Re:Editing changed the question, unfortunately by K.+S.+Kyosuke · · Score: 1

      For example, (map f (map g sequence)) might or might not be measurably faster than (map (lambda (x) (f (g x))) sequence). You won't know until you try. So this particular subtree of operations is a candidate for replacement. The process is rather generic and could be adapted to a wide range of problems: find possible transformations for the current tree, pick one of them, repeat until you hit a terminating condition. Do this non-deterministically so that you ultimately try as many diverse results as possible. The set of patterns and their replacements and the termination condition are problem-specific, the generic pattern is not.

      I've thought about ray tracing, actually. A lot of complexity in modern ray tracing implementations seems to stem from the interaction of programmable shaders with the tracing and sampling algorithms. I've peeked into this book, which is otherwise very nice, but the code made wonder "what if one could generate and run specialized versions of it on demand, instead of the few hardcoded special cases?". I suspect that solutions like the Open Shading Language are heading in this direction already. Now, with SPIR-V on the horizon, the idea is more appetizing than ever. You don't have to generate C at all here.

      --
      Ezekiel 23:20
  30. Re:Why? Just why? by K.+S.+Kyosuke · · Score: 1

    Are you implying that functional approach doesn't play well with vectorized code? If so, the APL family of languages would like a word with you.

    In fact, Lisp's compiler macros are probably the place where you'd want to plug in a custom vectorized code generator "for any vector units available".

    --
    Ezekiel 23:20
  31. Re:Why? Just why? by K.+S.+Kyosuke · · Score: 1

    Actually, twisted people use Python. ;)

    --
    Ezekiel 23:20
  32. Lisp by Anonymous Coward · · Score: 0

    Isn't Lisp something used by queers?

    1. Re:Lisp by Anonymous Coward · · Score: 0

      Like developers at Naughty Dogs for Uncharted 2?

      http://www.slideshare.net/naughty_dog/statebased-scripting-in-uncharted-2-among-thieves

  33. Re:Why? Just why? by RightwingNutjob · · Score: 1

    I'm not saying that functional is the correct paradigm to replace event-driven as typically used in those places. I'm saying that for working with the actual equations for the system dynamics for some large multi-state model, functional can be cleaner as in fewer lines of code to wrap your head around. But: its output needs to be usable inside a good old fashioned C program which implements the state machine event loop.

  34. The slashdot of Christmas' Past... by johannesg · · Score: 2

    It's like the old slashdot rose from the grave one more time... Don't worry kids, tomorrow we'll be back to stories about windmills and mobile phones, I'm sure.

    Apparently there is a kind of magic in LISP that is not in other languages. I studied LISP for a while to see if I could get a sense of this magic, but failed miserably - it never clicked, there was never any sense of enlightenment. Is LISP elegant? Not in my eyes. It's a mess of brackets, weird syntax, and strange symbols.

    At the same time, the attempts to write software with "C-like words, but with LISP syntax" is almost endearing. "Look, now you can actually have a switch-statement with strings in it!" they proudly exclaim, failing to note that this new statement only exists in their personal version of C, rather than in standard C. Who exactly is the target market for this new type of switch statement? Neither the C community nor the LISP community is likely to want it, since neither side recognizes the syntax they are using in the first place.

    According to one of the links, the goal is this: "The syntax is more like C as this is more of a tool that is meant to bring C programmers into the Lisp world rather than pulling Lisp programmers into the C world." To that I say, "good luck with that". But hey, maybe they can get Linus on board and rewrite the entire kernel in LISP-in-C-like-form?

  35. Chicken by Anonymous Coward · · Score: 0

    Oh, Slashdot.

    All this babbling about "if you want performance, C blah blah" and no mention of Chicken, which is a Scheme to C compiler which is just one of the more prominent members of a long tradition.

    Granted, the original poster wanted just to have the (Commmon Lisp) macro expander, and C "beneath" it, but all this territory (and much more) has been explored there, so it'd pay to have a look.

  36. C + LISP -> Pliant by Hubert+Tonneau · · Score: 1

    The state of the art for code generation is not Lisp but Pliant.
    Basically the main difficulty with code generation is not to make it powerful, but have it generate meaningful error messages rather than crazy code when some bad source is submitted. Through the definition of 'Expression' and 'Instruction' notions, Pliant defined a clean way to encode a program at various stages, and the rules for the code generator. S-expresions plus syntaxical substitution with a Turing machine equivalent substitution engine as opposed to just macros will bring you the power, but only the power.
    For extra details, just read the articles on http://www.fullpliant.org/

  37. Limited work by DrYak · · Score: 1

    which only works as long as :

    - all of the strings are going to be at least longer than the integer type you're using
    (there is no 3-chars long string, when you cast them to uint32 for this hack)
    and/or you use proper padding everywhere.

    - the integer type you're using is long enough for the different string to be easily distinguishable by this point
    (i.e.: you're not having all of your string beginning with "keep..." when you're restricted to uint32)

    (and note that both previous point are more or less going in opposite direction but, well, that happens when using pesky things like "human readable language" and other such extremely verbose input data)

    - you don't mind garbage aliasing with valid string (both "disable" and "disaJGrmHbnl" resolve to the same uint32)

    - or simply use this hack to sort the string in various bins and then subsequently process more (using a second cast-as-a-number switch for the next chars, or using more standard string comparison). (e.g.: the case that detect all the strings beginning with "keep" will do a second switch to check keep-?WHAT?)

    In short: nice hack, but is come with so many short comings that it's best left for some internal tool and never exposed to user-data-facing usage (like the internet).

    --
    "Sufficiently advanced satire is indistinguishable from reality." - [Tips: 1DrYakQDKCQ6y52z6QbnkxHXAocMZJE61o ]
  38. Easy by aglider · · Score: 1

    With a program!

    --
    Sent as ripples into the electromagnetic field. No single photon has been harmed in the process.
  39. Re:C + LISP - Pliant by K.+S.+Kyosuke · · Score: 1

    I'm not sure that there's a limitation on the usefulness of error messages in a custom-written transformer. It can be as bad or as good as you like it. Lisp provides the hooks into the compiler, but you provide the code. The description on that page also very much sounds like what an application of OMeta could do.

    --
    Ezekiel 23:20
  40. Re:Why? Just why? by Anonymous Coward · · Score: 0

    My bad. I hadn't read up on Lisp, particularly on Common Lisp for over 20 years, and that was from a book from the times before there was a common Lisp.. Arrays are the obvious starting point for such a library of macros.

  41. Re:Why? Just why? by hlavac · · Score: 1

    Which version of Python? :)

  42. Re:Why? Just why? by Anonymous Coward · · Score: 0

    I forgot about Erlang. What are those telecom systems that were programmed with it other than event-driven, fault tolerant control systems?

  43. Reminds me that one thing by Anonymous Coward · · Score: 0

    Do you mean, like, Emacs?

  44. To quote Nancy Reagan: JUST SAY NO by Anonymous Coward · · Score: 0

    "Full Power of Common Lisp". what an oxymoronic statement. A more pertinent claim is that Visual Basic is the most powerful programming language ever.
    As are RUST, R, Javascript, Clojure, etc. simply because you don't have to worry about GHarbage collection. BAH. I'll believe NONE of these claims until someone actually writes a working OS in them (yes, I do know about JavaOS, and LispMachines, Inc.) And they survived (snark) because they were just that good, right?