12 ms·
D-Expressions: Lisp Power, Dylan Style (1999) [pdf]
- panic 9y agoAnother Algol-style language with a macro system in this vein is Honu (https://www.cs.utah.edu/~rafkind/papers/dissertation.pdf https://www.cs.utah.edu/~rafkind/papers/dissertation.pdf). It goes slightly further, allowing macros to do things like define new infix operators, and its layered approach (with an "enforest" step interleaved with parsing) is worth a look.
- mahmud 9y agoHolly smoke! The supervisor committee on that thesis is _heavy_. I'm so gonna study it.
- 616c 9y agoThere is a solid person who frequented here who was the last guy working on OpenDylan and mentioned he largely abandoned that for a new passion for Rust. Besides him, was that the last person really shepherding it?
- BruceM 9y agoThat is me. I haven't seen much development effort since I switched to Rust. But ... I would still mentor someone who wanted to work on it or do something with it.
- 616c 9y agoI was never at that level but still was very interested by your selfless work on OpenDylan. I was going through a Lisp adoration phase (not that it ended, really; one of many cycles I have) and found Dylan as "Apples prescient Lisp without parens from the future" elevator pitch and was surprised its tooling was better on Windows than Mac, basically because of you driving a very smally community of volunteers. Perhaps I need to take another look.
- lacampbell 9y agoDylan did so much right. Well - the syntax was too verbose - but optional static types, pure OO, multiple dispatch.. that's an amazing set of features that would make me very productive.
- bitwize 9y agoThe dream of the Lisp Machines is long dead. JavaScript Machines are our new reality.
- justinjlynn 9y agoThe machine doesn't matter. It's the machine that matters.
- mmalone 9y agoWorse is better, amiright? sigh...
- lacampbell 9y agoI'm excited about web assembly machines.
- pjmlp 9y agoIf at least JavaScript was worthy of being a Smalltalk successor.
- sillysaurus3 9y agoI've been working on a Lisp for the last couple of years. There's one major downside to reader macros / syntax extension: Your editor probably won't understand it, and in extreme cases won't know how to indent or read it. Note that Lisp macros do not suffer this problem because it still uses the standard `'(,"foo") syntax. (In fact it's somewhat remarkable that Lisp syntax can be described in shorthand so compactly.) Reader macros are a different beast. Let's say you want to add support for [] as indexing. You can do this: > (let l '(a b c) l[1]) "b" And this: > (let l '(a (b) c) l[1][0]) "b" And since the reader is under our control, it's easy to use a dynamic expression as the index: > (let (l '(a (b) c) i 0) l[(+ i 1)][i]) "b" If you try this, you'll find most Lisp editors work okay-ish with it. Now let's say you want to be able to do this: > (if x) { (print "hello") } This is entirely possible since we control the reader. The rule is, if the following expression is a curly-body, it gets converted into `(do ,@body) and inserted as the last argument of the previous expression. So it becomes: > (if x (do (print "hello"))) However, this fails hard inside of standard Lisp editors. You'll lose indentation right away. Nothing understands curly notation. For example if you turn on Clojure mode and try to auto-indent, here's what you get: > (if x) { (print "hello") } The alternative curly style is just as broken: > (if x) { (print "hello") } So if you expose this power to users, suddenly you have an editor problem: How can the editor know what to do with tokens, short of running the program? Even in Emacs, which is Lisp-based, it's not really possible to execute other Lisp variants. (I actually got both Scheme and Arc to work inside of emacs, which was amusing. No external programs; literally scheme, but running in elisp.) But even if it were possible, you wouldn't want to. An infinite loop would freeze your editor. Not to mention it should always be safe to open a file for editing, yet this breaks that safety guarantee. I think the solution is something like: > (define-reader ("{" s curly-body) ...) Within the define-reader block, `s` is the stream, and you can read tokens from it and return a result, or stuff the result into the previous token's last argument, or throw an error, etc. And since it ends with "curly-body", Lisp editors can be designed to detect this token and turn on "curly-body syntax" for any file that imports it. It's worth it. Would you believe this is Lisp? > require("fs").existsSync("/tmp") true It's equivalent to: > ((get (require "fs") "existsSync") "/tmp") But ten billion times more readable. And Lisp! I have no idea why Lisp doesn't let you call functions like foo(1 2 3) instead of (foo 1 2 3) It's an unambiguous transformation in every case. Nobody smashes an atom into a left-paren, ever. If there's an atom followed by a left-paren, or a right-paren left-paren combo, it means you want to call it as a function. It leads to some amusing situations: (list 1 2 3) list(1 2 3) But there's an easy solution: If it looks confusing, don't write it that way. Just like every other language feature. Even though Lisp is such an old language, I feel like we've barely scratched the surface. Clojure was a promising demo of what's possible. It's time for the next step.
- didibus 9y agoI know at first it looks confusing, but the lisp syntax is pretty much the best. I can teach it to someone in 1 minute: (<function or macro name> arg1 arg2 ...) That's it. This is 100% of the syntax. If dealing with a function, the evaluation will always be arguments from left to right are evaluated first, and then the function is called with the result of evaluating the args. This is 95% of the cases. If dealing with a macro, go read the documentation for it, because every macro is a DSL, and evaluation can happen in different ways. This is the 5% case. All the complexity of learning a lisp comes from knowing more functions, what they do and how to use them, and learning each macro's DSL. Can this syntax be improved on, I'm not so sure. Clojure added some special syntax for some more literals, such as [] for vectors, {} for map, etc. And I do think in one way they help, but in others they hurt. Maybe adding something that distinguishes a macro from a function, but once you know the names of them, the name is enough to know. Maybe make it so there is a more visible demarcation between the function/macro name and the arguments. Not sure how though. All that to say, if you give the ayntax a good chance, like 2 to 3 months of 40h a week for your brain to more clearly see where the functions start and end, I'm sure you'll like it.
- int_19h 9y agoThat something is simple and easy to explain doesn't necessarily mean that it's the best. Simplicity can hurt readability, for example, by utilizing too few distinctive visual patterns - fewer than human brain can easily distinguish while scanning code - and then having to reuse those same patterns for different things, making it necessary to pay more attention to finer details of the code to understand what it does. To give an analogy, imagine that we replaced all our punctuation with S-expressions. It would be simpler in conceptual sense, but do you think you could read such text faster than the one that distinguishes between commas, periods, question marks etc?
- lisper 9y agoThat's the wrong comparison. S-expression don't compete with natural language any more than C does. S-expressions compete with JSon and XML. And IMHO they win hands-down.
- patricksli 9y agoHello everyone. Since there's been interest in the D-expressions paper, I wanted to add that Jonathan Bachrach (the first author on the paper) is actually my Ph.D. advisor, and we just released a new programming language a few months ago called Stanza based on similar ideas. Stanza is a spiritual successor to Dylan of sorts: it has an optional type system, coroutines, a multimethod-based object system, programmatic macros, and an s-expression-based natural syntax. You can check it out at www.lbstanza.org. - Patrick
- such_a_casual 9y agoIt's pretty trivial to add macros to any language. The only thing that separates a macro from a regular function is time. In a normal function, the parameters are evaluated before being sent to the function. In a macro, the function is called before the parameters are evaluated. What separates lisp from other languages when it comes to macros is that the language is very simple and provides lots of tools for operating on the same data structure that you write your code in. Of course you can add macros to any language, that doesn't mean they'll be anything like Lisp macros, because you're still writing code that has many different ways of expressing function calls. Importing a file? Oh, don't call a function. Instead write this special syntax which will call that function for you. Declaring or setting a variable? Same shit. What if you wanted to do something really fancy like create a class, oh yeah, there's a special way of saying that too. So now when you go to automate this stuff, you've gotta teach your computer all the special different ways to write everything. Lisp isn't lisp because it has macros. Lisp isn't lisp because it's simple. Lisp isn't lisp because it has a lot of really smart ways of doing basic things that we take for granted (like explicit vs implicit scope on local variables). Lisp is lisp because it has them all. You can add the same extensibility that lisp has, macros, reader macros, operate on symbols, closures, whatever. You can do some of the really smart things that lisp does like explicitly scoping your variables or multiple dispatch. You can even have a really simple language, with a really simple syntax. But it's not Lisp's individual features that make it what it is, it's how these features interact with one another to give you something that's truly hard to replicate. Yes, of course you can replace a block of code with another, but how easily? For example, yesterday I was thinking about a variable that represents the result of evaluating the previous form. So instead of having to read a method chain backwards: (wax (buff (rinse (soap car)))) it could read forward: (soap car) (rinse ?) (buff ?) (wax ?) Now whether or not this is a good or bad idea is completely fucking irrelevent. The point is that it's an idea, and until an idea is tested, we have no idea how bad or good it is. In lisp, in 5 minutes, I can write a macro that wraps around a block of code and implements this idea so I can actually play around with it in the real world instead of just in my head. You literally just take a bunch of forms in, put a let statement around the whole block, and then put a call to set the variable around each individual form (If you're not familiar with lisp. a form is kind of like a line of code, it's usually a function call but it can be a value as well). In lisp I can have very abstract programming ideas and then immediately implement them, without having to fight through the language to do so (ie without having to write a parser). It's cool when other languages take stuff from lisp, it makes it easier to write lisp like code when I have to use other languages, but I've read a lot of articles on "Lisp macros in X Language" and none of them seem to understand that you can't just implement macros, you have to make the structure that code is written "first class". You have to give the programmer the tools they need to operate on a piece of code as naturally as they would a string, a number, or an array.