8 ms·
XL: An Extensible Programming Language
- tempodox 3y agoThis seems to be Prolog with a large dose of syntactic sugar.
- bradrn 3y agoMore Lisp than Prolog… I don’t see any constraint-solving here, just macros.
- mapcars 3y agoI don't see them as macros either, it's more like pattern matching and replacing patterns with expressions. Maybe there is a term for that? And it's not compile-time only, I'm pretty sure you can't do this as a macro: >loop Body is { Body; loop Body }
- bradrn 3y ago> it's more like pattern matching and replacing patterns with expressions Scheme macros use pattern-matching. > loop Body is { Body; loop Body } This, though, is definitely strange. I’m not quite sure how it works.
- c3d 3y agoYou can do exactly that, and this is how this is defined in the built-in library https://github.com/c3d/xl/blob/fast/src/builtins.xl#L222 https://github.com/c3d/xl/blob/fast/src/builtins.xl#L222 How it works is what I tried to document in the document above. The trick is to have some fixed semantics on how rewrites are done, but a lot of freedom in how this is implemented. And this is far from perfect ATM. For example, if you write "X is 2", this can be implemented as a constant, as a function returning a constant, or as a macro. However, if you write "X is seconds" in Tao3D, where "seconds" returns the current number of seconds in the clock, then it can no longer be a constant value. You still can use macro replacement (or inlining) or turn it into a function. More details here: https://xlr.sourceforge.io/#compiling-xl https://xlr.sourceforge.io/#compiling-xl
- Nevermark 3y agoIt's just a case of a pattern definition including references to itself, which are then linked to its definition before use. In the same way function definitions often contain reference themselves, which are linked to complete the definition. uint64_t alignBitsLeft(uint64_t x) { return ((x >> 63) == 1)) ? x : alignBitsLeft(x << 1); } The pattern "alignBitLeft(uint64_t)" definition starts in line 1, but is not completed until line 3. Yet line 2 references that pattern, before the definition is complete. This works, because of a linking step at definition completion, where the "alignBitsLeft" reference gets linked to the now complete "alignBitsLeft" definition. Similarly for: > loop Body is { Body; loop Body } The "loop Body" definition beings, including a reference to itself. Once the whole definition has been built up, the "loop Body" reference gets linked back to the "loop Body" definition. Ready for use. -- Another way to look at this is memoization (at compile or run time). When you evaluate the second line of this: n is 1; loop { print n; n is n + 1; } You get this: { print n; n is n + 1; loop { print n; n is n + 1; }} If we cache that definition before evaluating it, when we get to the embedded loop clause, we don't need to compute it again. We have already computed that exact loop pattern before and can reuse the result (over and over).
- c3d 3y agoThere is no backtracking, but being able to implement Prolog on an XL basis was an important part of the original design of the "runtime" version of XL.
- netbioserror 3y agoSeems cool. But I'm not convinced extensible languages benefit from adding a variety of syntactic forms. As your ability to extend the feature-set increases, the need for a single regular syntactic form increases. Lisp may not be appealing to beginners because of its parenthesis, but they absolutely are what makes it work so well for its intended use cases. Really, all use cases. I'm actually a fan of the parenthesis. Lisp feels like aesthetic perfection to me. Languages like Haskell and XL here just look like line noise to my brain.
- mapcars 3y agoThere are lisps without parens too, it's not strictly required for parsing and evaluation. I think the main purpose of parens is to highlight the syntax tree for developer manipulations with macros
- diggan 3y ago> There are lisps without parens too Are there any that come close to the usage of lisps with proper s-expressions? I've seen them come and go, but no "lisp without parens" that seem to stick around for longer period. I guess that should say something? Maybe we just haven't found the right way of exposing it though. Personally, when I've given it a try, the indentation-based syntax always makes it hard to use without faults. Maybe it's just a "getting used to" thing, but it seems like a mistake to depend on invisible characters for syntax. FWIW, I hardly ever write macros (mostly use Clojure/Script), so not sure the main purpose of the parens is macro writing for me. S-expressions with something like parinfer just makes programming a lot more enjoyable and easy, especially compared to all the C-syntax-like languages.
- tehologist 3y agoI am pretty sure logo is mostly a lisp without parenthesis. I find it a lot more readable than most lisp dialects. I am not sure why it never caught on.
- 3y ago
- throwaway17_17 3y agoI would really like to see more discussions about the difficulties using LLVM can create for smaller language projects. The entire PL ecosystem is hyped up to revolve around the project, but rarely do you see language designers and solo/small group devs talk specifically about problems relying on LLVM. The history section of XL’s page cites non-commitment to code compatibility between releases as their big struggle, which is a change from the more common complaints of inherent complexity and compilation time. I’d love to see more discussion of this, and maybe, see a focus on smaller backends and code generation tools for compilation, like QBE. Anyone with recommendations for reading would be welcome to dump those here.
- c3d 3y agoI specifically addressed some of these topics in this talk: https://www.youtube.com/watch?v=Xzo7GIoDgAo https://www.youtube.com/watch?v=Xzo7GIoDgAo
- Arelius 3y agoFor sure this. I have a little compiler from 10+ years ago I was working on. And I recall after I had put it down, and tried picking it back up just maybe a year later(?) The interfaces I was using in llvm all changed. It really took the wind out of my sails for jumping back in.
- c3d 3y agoI realized I forgot to share my most memorable piece of code ever: llvm-crap (Compatibility Restoration Adaptive Protocol) https://github.com/c3d/xl/blob/master/src/llvm-crap.h https://github.com/c3d/xl/blob/master/src/llvm-crap.h
- c3d 3y agoThe really ugly stuff is here: https://github.com/c3d/xl/blob/master/src/llvm-crap.cpp https://github.com/c3d/xl/blob/master/src/llvm-crap.cpp
- sixthDot 3y agoFrom what I can read the author got really unlucky with some kind of radical API changes. Maybe at that time the LLVM team was a bit less serious with deprecations ? I use LLVM since v9, nowadays I'm stuck on v15 (that's not because of LLVM btw). Between the two versions there's been a radical change too, i.e "opaque pointers", but the transition was rather smooth as we were provided, for a long time, the two versions of the functions affected by the change. Maybe the LLVM team got more serious since the author experienced the said difficulties ? Other thing I note is that the author uses the CPP API. I use the C one which exposes only a high-level subset of the CPP one. This encourages a saner use of LLVM, a more concrete separation between the front-end and the mid-end, although sometimes there are limitations. A simple example of what encourages the C API, especially since opaque ptrs are added, is not to rely on LLVM to retrieve the IR type of an IR value. That should always be done using the AST, eg with an `.ir` field in your nodes. Another one I remark, after a brief overview of LLVM-CRAP, is that the author had to change the internal data structure used, depending on the LLVM version [0]. Using the C API that would never had happened. The C API essentially allows to create block refs, instructions refs, value refs, type refs, contexts. Then you choose the containers you want to use to hold them. No need to switch to another stdcpp one, even if internally LLVM does so. [0]: https://github.com/c3d/xl/blob/master/src/llvm-crap.cpp#L265 https://github.com/c3d/xl/blob/master/src/llvm-crap.cpp#L265
- nurettin 3y agoFollowing the "is" operator sections, I half expected it to build up to prolog facts, and then solve the zebra puzzle.
- cb321 3y agoThose interested in XL may also find the much older GalaxC by John Beetem interesting: https://community.element14.com/technologies/fpga-group/b/blog/posts/xxicc-21st-century-co-design https://community.element14.com/technologies/fpga-group/b/bl...
- c3d 3y agoWhy do you think it's older? XL started as LX around 1993, and IIRC self-compiled in 2004 or so.
- cb321 3y agoI am looking at a 1989 paper by Beetem & Beetem [1] but then it was called Galaxy.. I agree "much older" might be a bit.. much. Haha. EDIT: Joking aside, I would love to hear a compare & contrast between Galaxy/GalaxC & LX/XL, though!! EDIT2: and via that first link, I think you can get to a full source code distribution compile-able with C on 32-bit Linux. Might have its own woes like LLVM hosting, but those might also be more solvable as part of a 64-bit port. [1] https://ieeexplore.ieee.org/abstract/document/28124/ https://ieeexplore.ieee.org/abstract/document/28124/
- thechao 3y agoI'd like C, but where I could use some syntax like: typedef _Load("libvector.so")(int) vector_int; to add arbitrary "builtin" types to the language. The idea being that "libvector.so" would use some spec-defined API to extend the core C language with the new features. This would replace a slew of features in the core C++ language (templates, classes, any sort of reflection, etc.), with some sort of 3rd party dylib you load. The idea is to keep the core language simple in the sense that it doesn't contain its own extension mechanism as syntax. I think my only worries would be how to handle life-time analysis, i.e., the moral equivalent of destructors, copy constructors, move-semantics, etc; maybe the dylib ('libvector.so', in this case) has to register stack-clean-up, copying, and move-semantics code-generation for the compiler?
- 5- 3y agotake a look at https://pdos.csail.mit.edu/archive/xoc/ https://pdos.csail.mit.edu/archive/xoc/
- thechao 3y agoHey, neat! However, this line of research (which I'm passingly familiar with) is about extending the grammar of the host language (for Xoc: C), along with the semantics (for Xoc: the Zeta interpreter). I think I'm interested in a slightly rotated design space: the C grammar is left alone[1]; instead, an extension of the C spec defines a specific API for (effectively) code injection; and, finally, we limit ourselves to new types and functions, possibly with non-standard sizing (`sizeof`/`alignof`/...) information. [1] Modulo the introduction of `_Load("...")(__args__)`, and a few other function-like invocations.
- djha-skin 3y agoObligatory "lisp has had this for ages". Herein, macros seem to be invented from first principles, having only been exposed to imperative languages like C++. It is interesting to see macros here invented in the context of a language that is not homoiconic. I wonder how it stacks up against Rust macros.
- bradrn 3y agoHe claims it is homoiconic, though: https://xlr.sourceforge.io/#homoiconic-representation-of-programs https://xlr.sourceforge.io/#homoiconic-representation-of-pro...
- simplify 3y ago"What is homoiconicity then? Typical definitions state that it is simply “code as data”, will point to a relationship between a program’s structure and syntax or note that the program source is expressed in a primitive data-type of the language. In the below, we will show that none of these definitions make much sense." https://www.expressionsofchange.org/dont-say-homoiconic/ https://www.expressionsofchange.org/dont-say-homoiconic/
- lebuffon 3y agoObligatory "FORTH has had this for ages". :-)
- runlaszlorun 3y agoIs Forth really homoiconic? I’m asking as a recent fan of Forth. I would’ve thought to describe it as having strong, interactive metaprogramming but not necessarily homoiconic. Unless ‘code = data, data = code’ because they’re all bytes… haha. Postscript would count as homoiconic, I’d think. Though I haven’t actually seen programs that so this.
- crq-yml 3y agoI think Forth counts, in a "Turing-complete" sense of homoiconicity. A Forth program in a classic indirect threaded system can self-modify, reach in and change core interpreter words during execution. But it isn't obeying any formal soundness principle, since it's just a thin layer over the machine. Compiled Forths might opt to wall off some of those options behind the compiler interface, in effect making the language slightly less far-reaching.
- DonHopkins 3y agoWhat does "is is is" mean in this language? Maybe it's a quine? Can you define an "isn't" operator?
- runlaszlorun 3y ago“is is is” would be called BillClintonLang, no?
- fuzztester 3y agoOr TrumpLang. "It is what it is". https://www.google.com/search?q=Trump+it+is+what+it+is https://www.google.com/search?q=Trump+it+is+what+it+is 2nd hit onwards.
- runlaszlorun 3y agoOh man. I’d missed that Trumpism.
- c3d 3y agoLet's ask the interpreter / compiler: ./xl -nobuiltins -parse /tmp/glop.xl -style debug -show (infix is is is ) So what it sees is a definition of a name 'is' as itself. Now, that name is very unlikely to be usable because `is` as an infix is so central to everything. As a matter of fact, it looks like even "is is 2" actually crashes the current implementation. Oh well. I wonder what a sensible error message on this would be. Probably: "Bill Clinton denied to comment on the meaning of that statement".
- runlaszlorun 3y ago> "Bill Clinton denied to comment on the meaning of that statement". Oh man, that’d be hilarious. I’ve been hacking around with my own sorta Forth/Postscript like attempt at a language that runs on WebAssembly and does graphics in the browser. Odds are it’ll never see the light of day. But if it does, you’ve now triggered all kinds of ideas for ridiculous ideas for error messages. Like starting them of with ‘hey bruh…’ or trotting out good ol’ Mr Clippy from Microsoft.
- maxpert 3y agoMaybe a good DSL language. But I will avoid adding such complexity to my daily programming language at all costs.
- dkjaudyeqooe 3y agoI've been working on something centered around extensibility, or metaprogramming, coming from a strictly imperative angle, with the belief that anything else (functional, relational/logic based, whatever) can be built on top of that. A few guiding principles are: - simplicity above all, with as few fundamental elements as possible - the parser is a separate issue, just write your own syntax to avoid the most divisive bikeshed element of PL design, or pick the C like or ALGOL like one out of the box. You very likely want your own syntax anyway as you write extensions. - every language element, from modules down to function calls, are first class, ie have an (implementing) type, can be stored in variables and used in expressions, be introspected and evaluated/deployed. - runs at compile time, compiles at run time (code generation/partial evaluation/dynamic code) - generates C, Java, Python and various bytecodes to maximise interoperability, code availability and deployability - has no standard runtime or standard library of its own, is entirely parasitic on other environments Even if it ends up being completely useless, it's a really interesting exercise in design.
- TOGoS 3y agoThat's interesting, because I've been 'working on' something with all those same bullet-points. I'd be interested to hear more about your take on this! Some notes on my lack of progress: http://www.nuke24.net/plog/43.html http://www.nuke24.net/plog/43.html
- runlaszlorun 3y agoQuite an ambitious offering by the author. Kudos to him/her. I have my own little (overly) ambitious language effort in a different direction and tend to beat myself up a bit since I feel like I should have more to show after almost 4 years. Then I noticed in the author’s history section towards the end that they’d been working on this sine the early 90’s and felt better about that.
- runlaszlorun 3y agoOther than here, are there any other places online where folks writing their own languages tend to congregate? Having recently joined that tribe, I think it does take a particular worldview and type to be willing to undertake that. I suppose folks writing an OS perhaps even more so.
- dmux 3y agohttp://lambda-the-ultimate.org/ http://lambda-the-ultimate.org/ is one of the only PL-centric websites with discussion I can think of.
- runlaszlorun 3y agoAh yes. I know it but haven’t been there in a long, long while. Thx.
- throwaway87651 3y agohttps://old.reddit.com/r/ProgrammingLanguages/ https://old.reddit.com/r/ProgrammingLanguages/ For fun: https://esolangs.org/wiki/Main_Page https://esolangs.org/wiki/Main_Page
- runlaszlorun 3y agoThx. I’ll check them out.
- c3d 3y agoAuthor of the project here... Weird to see this generates such a discussion when the project is something like 20 years old, and has been quasi-dead for a while now ;-) An interesting derivative of XL is Tao3D, which shows what you can do with it. https://tao3d.sourceforge.net https://tao3d.sourceforge.net A FOSDEM workshop about Tao3D (which includes initiation to XL): https://www.youtube.com/watch?v=uE9LwSuZD64 https://www.youtube.com/watch?v=uE9LwSuZD64 The design philosophy, and why it's not "just another Lisp" is here: https://xlr.sourceforge.io/Concept%20Programming%20Presentation.pdf https://xlr.sourceforge.io/Concept%20Programming%20Presentat...
- runlaszlorun 3y agoWell, quite an ambitious and impressive piece of work. And as I mentioned elsewhere here, reading your history made me feel a lot better about not having a ton to show after 3-4 years, haha.
- pkjens04 3y agoHow does this compare to http://flexipl.info/ http://flexipl.info/ Iirc backend and goals seem quite similar.
- mapcars 3y agoI never heard about XL and it looks very interesting, the DSL capabilities remind me of Rebol/Red, but it looks like XL has a proper type system and compile-time optimisations. What is the current status the project? Is there any ongoing work and plans?
- c3d 3y agoThe current state is "on backburner by lack of time". Projects like https://grenouillebouillie.wordpress.com/2022/03/07/a-theory-of-incomplete-measurements/ https://grenouillebouillie.wordpress.com/2022/03/07/a-theory... and https://github.com/c3d/DB48X-on-DM42/tree/stable https://github.com/c3d/DB48X-on-DM42/tree/stable have been consuming most of my spare time cycles. Here are factors playing a role in my current thinking: 1/ the LLVM debacle. I just can't follow them changing the APIs all the time. I gave up on LLVM for now. 2/ Rust being the first language introducing a concept that was not trivial to introduce via an XL library, lifetimes. I think that I nailed a design now, but it annoyed me for a while, and the design is not implemented. 3/ I spent some time documenting where I wanted to go, notably the type system. As a result, I found that the language was becoming complicated, which annoys me. I'm trying to get back to super-simple roots, but I have no clear path towards this goal yet. 4/ I want to to unify the self-compiling compiler and the dynamic one. The self-compiler only compiles an older dialect of the language.
- runlaszlorun 3y agoAnyone know of other languages using pattern matching as a foundation? I’ve come across Refal[1], who’s creator Valentin Turchin seems like someone who hasn’t gotten the recognition he maybe deserves. As an aside, his son Peter Turchin does some interesting work in a different direction that’s def topical these days. I know SNOBOL gets labeled as one. Would Prolog count? I haven’t actually written any myself. They def make a strong appearance in Erlang, though it isn’t the first thing that comes to mind if describing. There’s XSLT of course. Any others? I think if one were only able to pick one metaphor for a language, I think a strong case could be made for: pattern => behavior [1]https://en.wikipedia.org/wiki/Refal https://en.wikipedia.org/wiki/Refal
- c3d 3y agoCheck out Pure. https://agraef.github.io/pure-lang/ https://agraef.github.io/pure-lang/ This was what convinced me to switch to LLVM. I now regret that decision, but at the time, it sounded like a lot of fun.
- runlaszlorun 3y agoThx, I’ll check it out.
- jinwoo68 3y agoProlog is based on "unification" in large part, which can be considered advanced pattern matching.
- shrubble 3y agoAre you using pattern matching in the sense of Standard ML and the ML family of languages?
- runlaszlorun 3y agoProbably but I don’t know any ML… lol. I’ll def check it out though so thx!