8 ms·
I am scratching my head. If we are parsing S-expressions... why not embed Scheme already? This way, not only you get an S-expression parser for 'free', you can
by outworlder 6y ago
I am scratching my head.
If we are parsing S-expressions... why not embed Scheme already? This way, not only you get an S-expression parser for 'free', you can easily manipulate S-expressions, you can add macros and so on. And you also get your scripting language out of this deal!
Something like Racket or Chicken (and possibly others) would work nicely. Chicken specifically has a very nice FFI - which you don't even have to use. As an experiment, I have asked Chicken's compiler to stop at the C code generation, added the generated code to my XCode project, and deployed the whole package to iPhone. Not even cross compilation shenanigans were required, since this was handled by XCode.
As a bonus*2, with a few lines of code, I opened a TCP listener, and fed straight to the REPL. Which meant that I could telnet and have a REPL, which could be used to replace functions on the fly and observe the results immediately, while the app was running.
They would have to rename the project at this point, though :)
- codemac 6y agoguile for embedding works really nicely.
- outworlder 6y agoSorry, I keep forgetting about Guile. That thing needs more love indeed.
- grugagag 6y agoAs a newbie im getting a bit confused. What is the difference between guile and chicken scheme? There's also chez. Im even more confused
- deleted 6y ago[deleted]
- outworlder 6y agoThese are different implementations. The language spec they follow is slightly different so they are not completely compatible (although I've been able to use some OpenGL-ES Racket code with no modifications in Chicken by using macros). Where they will differ the most is things like the packaging system (if they have packages, not all Scheme implementations will), as well as their main use-case. If you are interested, just pick one and start to learn Scheme, using any implementation. Their differences will become apparent quickly.
- grugagag 6y agoThank you. Quite a few options out there in terms of LISPS and a beginner like me can be quite confused. I started looking at SBCL, Chicken Scheme and Racket and since I'm a newbie I'll stick with racket for the learning phase. I seem to like more the uniformity of Scheme over the cl for example. Do people usually specialize in one or the other or use them interchangeably depending on libraries and such? Another slight barrier has been learning Emacs and that's another reason I chose racket. I like what Emacs is capable but I most likely revisit later.
- minerjoe 6y agoRacket can be a good first choice. I would nudge you, if I may, and if the lisp glove fits, into taking the deep dive into emacs + evil (optional) + paredit + SLIME/SLY + SBCL + Quicklisp There are fully configured starting setups out there for a quick start. That's basically the closest thing nowadays you'll get to experience the interactive power of the ol' Lisp Machines. That said, you might not always need such large runtimes and other lisps can fit the bill. For example, I usually program in CL (with C FFI) for most projects, but for embedding lisps into existing C programs, Guile can be a joy. Once I was programming servo motor controllers that offered C as one of the programming languages, and I embedded a single C file that gave me a tiny little scheme interpreter and I was then able to prototype motor control algorithms and setting in way less time than before. It's just a game changer for learning about a system when you can get a REPL on it and start rapidly digging and experimenting.
- 6y ago
- Jtsummers 6y agoThey're each different implementations of Scheme, sometimes with different design goals (like embedding or scripting or for standalone programs). Scheme is a pretty simple language (in comparison to many others) and relatively small. There are also several versions (not just implementations). Common ones out there now are R5RS, R6RS (it was considered "big" and was somewhat unpopular), and R7RS. Consequently, different implementations are also conforming to different versions of the spec. Really, if you're wanting to learn Scheme, just pick one and run with it. For learning purposes they're mostly equivalent if you stick to the more popular ones, but be aware of your learning material and the version of Scheme that they're using. If you're familiar with other programming languages, it's somewhat like the relationship between different compilers. Though usually they adhere a bit more strictly to the same standards. Since Scheme is such a small language, there's more room for differences between implementations. This mostly doesn't affect you as a learner (most learning materials focus on the core parts of the language which all implementations should be consistent on).
- grugagag 6y agoThank a lot, I decided to give Racket a go. It has a fancy IDE and is battery included
- Jtsummers 6y agoCool. Racket's a great option, and it's really a multi-lingual environment. Technically not Scheme anymore, but compatible with it in most ways. So any learning material for Scheme will still apply, and you can select different Scheme versions within Racket if the Racket language itself is incompatible with whatever book or similar you're using.
- cycloptic 6y agoThere is a basic explanation that was written by the guile maintainer in 2013: https://www.wingolog.org/archives/2013/01/07/an-opinionated-guide-to-scheme-implementations https://www.wingolog.org/archives/2013/01/07/an-opinionated-...
- svvcfb1212 6y ago...and this is how we get unnecessarily bloated software with ungodly dependency chains and complex build systems. Sometimes a purpose-built module that addresses the need and maintains simplicity is preferable over complexity in the interest of some future potential feature that nobody has asked for yet, and may never ask for.
- outworlder 6y agoThose Scheme interpreters are tiny! I can guarantee you that a game will need a scripting language. Better get that done already. That's if you prefer Scheme. You could use Lua too.
- learc83 6y ago>I can guarantee you that a game will need a scripting language. Better get that done already. Myself and thousands of people before and after me have written games without a scripting language.
- outworlder 6y agoYou _can_ write a game without any scripting language support whatsoever. You could also write the whole game in assembly if you so desired. However, if every single time you want to change any piece of logic in your game, you have to do the edit/compile cycle, your development will be extremely slow. Especially if you compare with the ability to change code while the game is running. Not having all the game logic in C or what have you makes the game easier to mod too.
- pengaru 6y agoFast iteration can be achieved with compiled game logic as well, it all comes down to how things are factored in your project. An excellent example most with OpenGL experience may be familiar with is supporting hot reloading of GLSL for fast vfx development iteration. It's a compiled language, it gets compiled at runtime without significant delay, and most of us making games have created simple tools to support live editing of GLSL, maybe even supporting it in-game for dev builds. The demoscene has even turned it into a form of competitive performance art: https://github.com/Gargaj/Bonzomatic https://github.com/Gargaj/Bonzomatic Edit: Forgot to mention Casey also goes through support of hot-reloading game logic using C in the Handmade Hero series on YouTube.
- grugagag 6y agoYes, preferably chicken scheme as the compiled c code is snappier. I was just looking at chicken scheme on a pocketchip, admittedly I am just just scratching the surface with lisps but this is so cool. For learning I find racket to be quite good but chicken seems a lot better at performance. How long have you been a lisper? Newbie here
- samatman 6y agoIt wouldn't be a C project if it didn't embody Greenspun's Tenth Rule.
- vrnvu 6y agoLet me google the rule for those of you reading. "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp."
- platinumrad 6y agoBecause he needs to parse some config files, not embed a second language.
- tgb 6y agoThe author does say the following: > I'd rather be as library independent as possible, ideally with my SDL being my only cross-platform dependency to worry about.
- lurquer 6y agoAll you professional programmer-types seem to have forgotten that solving problems (even if they’ve been solved a thousand times before) is FUN. I wrote a custom-made script parser... knowing full-well there were many libraries available. (For a goofy program I wrote available at cycell2d.com) Why? Because I enjoyed it!
- rumanator 6y ago> If we are parsing S-expressions... why not embed Scheme already? This sort of nonsense is a good example of how some projects die due to absurd feature creep that no one at all can possibly justify. Who in their right mind would ever want to embed a full blown scripting language if your usecase is... Open a file and input data? If you want to input data following a document format, you parse the document format. That's it.
- Reelin 6y ago> Who in their right mind would ever want to embed a full blown scripting language if your usecase is... Open a file and input data? Because embedding a mature, well written dependency that fully satisfies all your requirements might well be easier from a technical standpoint. It's certainly likely to reduce your comparative future maintenance burden given that the upstream community is healthy and functional.
- rumanator 6y ago> Because embedding a mature, well written dependency What? Are there no mature well written parsers? Don't be ridiculous.
- Reelin 6y agoI thought the comparison was between embedding a Scheme or implementing your own sexp parser from scratch. Of course embedding a good sexp parser is also a valid option to consider, I'm not that dense. Granted that in this particular case the point seems to have been the exercise of implementing the parser itself so embedding a dependency wasn't a valid approach to begin with.
- lc9er 6y ago> I could telnet and have a REPL, which could be used to replace functions on the fly I thought you had to restart a scheme’s REPL. Is that just a limitation of Racket?
- DonaldFisk 6y agoAt the top of the page, Ben writes that he's a "Functional Programming Enthusiast", so he'll at least have a vague familiarity with Scheme and similar languages, even if he doesn't use them. S-expressions are a widely used standard data format and are not exclusive to Lisps. If this is just to read in configuration files, and the resulting data structures never change after they're read in, he can get away with using calloc instead of a garbage collector, and null-terminated char * C-style strings. Lisps (including Scheme) have more heavyweight implementations of strings and symbols than Ben has here, with an extra level of indirection: a symbol's name slot points to a string struct, which contains a pointer into an array of chars and a length. He can get away with a null-terminated char * and a struct containing an enum to distinguish them. For Lisp programming, the extra complexity is essential but for reading a config file into a game written in C, it's accidental. I don't know what kind of game he's writing but presumably it isn't anything like Abuse or Crash Bandicoot. In the first paragraph, he writes, "I turned away from XML because I'd rather be as library independent as possible." This implies that he might have considered embedding a Lisp but decided against it for the same reason.
- deleted 6y ago[deleted]
- grumbel 6y agoTuring-completeness is not just a benefit, it also puts a huge maintenance cost on you. An S-expression is something you can edit in your level editor, process with a script or do a lot of fun stuff with. It's just data. You can even convert it to JSON, XML or binary if you ever get tired of S-expressions. Once you are no longer dealing with data, but with actual Scheme code that is no longer the case and it becomes virtually impossible to do anything with the code other than directly editing it in a text editor. It's extremely inflexible and every tiny API change will break everything with no automatic way to fix it.
- unoti 6y ago> If we are parsing S-expressions... why not embed Scheme already? I agree. I just thought the goal of the author was to produce a game, not to parse S expressions. It’s possible that parsing S expressions is the most direct route to get there. But there may be more direct and simple ways to get there.