[HN Gopher] Mal - Make a Lisp ___________________________________________________________________ Mal - Make a Lisp Author : AlexeyBrin Score : 139 points Date : 2021-04-24 12:15 UTC (10 hours ago) (HTM) web link (github.com) (TXT) w3m dump (github.com) | progre wrote: | One interesting thing about this project is the extensive use of | Make. Not only is the test suite Make based, there is also a Mal | implementation in Make | harryvederci wrote: | If I recall correctly, the project started as "Make Lisp" (a | lisp made with Make), and later changed to "Make A Lisp". | macintux wrote: | I attempted this a few years back, didn't get far before I got | hung up on the regular expression(s) required for parsing. Silly | to get stopped there, but there was just enough friction between | the specified expression, the language I was using (Erlang), and | my understanding of the subtleties that I punted. | | I think with Regex101 in my back pocket I'll give it another try. | | https://regex101.com | progre wrote: | I also could not get the regex to work, so I ended up writing a | custom tokenizer. It ended up being like 30 lines of code, and | unlike the regex I could understand how it works | agumonkey wrote: | Brown University PLT textbook used lisp/scheme and their first | paragraph was something like "nobody cares about parsing, let's | get down to business in sexps" | | I like parsing, I like regexes but I agree it's often a waste | of time :) | duncaen wrote: | Regex to parse lisp expressions? | bgorman wrote: | The regex is used as a tokenizer, the outputs of which are | then fed into the reader module. | the-smug-one wrote: | Regexes are at least useful for parsing numbers and symbols. | | But yeah, that shouldn't be where you get stuck. | macintux wrote: | [\s,] _(~@|[\\[\\]{}() '`~^@]|"(?:\\\\.|[^\\\"])_"?|;. | _|[^\s\\[\\]{}( '"`,;)]_) | | Step 0, so I didn't get very far. | | https://github.com/kanaka/mal/blob/master/process/guide.md# | s... | cellularmitosis wrote: | Whoa that regex is a monster. Try starting with simpler | pieces and see if you get further this time around. Good | luck! https://gist.github.com/cellularmitosis/75dc4aefe88 | 438c14e94... | SanFranManDan wrote: | If you are using erlang you should be using pattern matching | not regex. Erlang/Elixir are one of the easiest languages to | build parsers in with their binary string pattern matching. | macintux wrote: | I agree, pattern matching is what I sorely miss every time I | use anything other than Erlang. It's just enough of a hurdle | I set it aside and didn't return. | | It's a big step. | | https://github.com/kanaka/mal/blob/master/process/guide.md#s. | .. | KineticLensman wrote: | In C#, I ended up with static public | List<string> Tokenizer(string source) { // | Initialise the token list. List<string> tokens = new | List<string>(); // Define a regex pattern whose | groups match the MAL syntax. string pattern = @"[\s | ,]*(~@|[\[\]{}()'`~@]|""(?:[\\].|[^\\""])*""|;.*|[^\s | \[\]{}()'""`~@,;]*)"; // empty ~@ | | specials | double quotes |; | non-specials | // Break the input string into its constituent tokens. | string[] result = Regex.Split(source, pattern); | | This took a while to understand and get going but it really | improved my understanding of regex. | tom_mellior wrote: | I went through this a while ago (in Prolog). It was interesting, | but with a lot of room for improvement. My criticisms as I | remember them: | | - Error messages about output being different from the expected | use some sort of very explicit printing mode with lots of quotes | and escaping. A message saying that one got "\\\\\'\\\\\'" where | "\'\\\\\\\'" was expected is needlessly hard to parse when the | actual difference is \'\' vs. '\\\' (or whatever). | | - Many parts are marked optional, but the test script complains | if you don't implement them, and later sections assume that they | are implemented, so you have to treat them as compulsory anyway. | | - Some things regarding environment updates were contradictory or | at least not explained properly at first, with some very relevant | information only coming later. I don't remember the specifics, | but the problem was roughly that I set up my data structures | thinking that everything could be implemented in a pure way, but | at some point it became clear that you either need some other | data structure or must use destructive modifications. | miloignis wrote: | I went through MAL last year and had a blast! It's an excellent | project to help you get a feel for Lisps and tiny languages, and | I think is what finally got me over my "eww parentheses" feeling. | After finishing MAL, I modified it to implement John Shutt | Kernel-style f-exprs to really up the power-to-weight ratio, and | had a blast doing it. MAL makes a great basis for experimenting | with additional language features, highly recommended! | diminish wrote: | I liked MAL similar to Linux from scratch (LFS). | Y_Y wrote: | Interesting languages that aren't on the list of implementations: | APL/J/Kx Verilog Fortran LISP 1.5 | jmrm wrote: | Also COBOL and VHDL. I don't know how a hardware description | language could implement a Lisp variant btw. | Y_Y wrote: | They actually do include a VHDL implementation! COBOL would | be cool though. | rjsw wrote: | There is a Verilog implementation of the MIT Lisp Machine. | sedachv wrote: | > I don't know how a hardware description language could | implement a Lisp variant btw. | | https://dspace.mit.edu/handle/1721.1/6334 | nicklecompte wrote: | I was a bit surprised nobody's tried a "verified" | implementation in something like Coq/Idris/Agda (unless i | missed one - I wasn't familiar with all the languages in the | list). | | Might be a fun project! | pygy_ wrote: | This is unintentional given the history of the name of the | project explained in another comment on this page, but "mal" in | French means "evil", tying into the famous aphorism. | rbonvall wrote: | In Spanish it means "badly", which is an encouraging goal to | give the project a try :) | KineticLensman wrote: | I did this a while back. I documented my experience in several | blog posts, the last of which is [0]. These describe the process, | the gotchas and how I got round them. I was working on C# on a | Windows box so the result isn't quite the same as the vanilla | MAL. | | I was massively pleased when I got MAL to self-host. | | [0] https://www.non-kinetic-effects.co.uk/blog/2019/04/28/MAL-5 | dang wrote: | If curious, past threads: | | _Mal - Make a Lisp, implemented in 79 languages_ - | https://news.ycombinator.com/item?id=21670442 - Nov 2019 (11 | comments) | | _Mal - Make a Lisp, in 68 languages_ - | https://news.ycombinator.com/item?id=15226110 - Sept 2017 (69 | comments) | | _Mal - Make a Lisp_ - | https://news.ycombinator.com/item?id=12720777 - Oct 2016 (1 | comment) | | _Make a Lisp_ - https://news.ycombinator.com/item?id=9121448 - | Feb 2015 (41 comments) | | _Lisp implemented in under 1K of JavaScript_ - | https://news.ycombinator.com/item?id=9109225 - Feb 2015 (16 | comments) ___________________________________________________________________ (page generated 2021-04-24 23:00 UTC)