6 ms·
The super advantage of Lisp (including Scheme): Its format for defining data is the same as for writing code, making macros a natural part of the syntax: You ca
by ArneBab 10y ago
The super advantage of Lisp (including Scheme): Its format for defining data is the same as for writing code, making macros a natural part of the syntax: You can change your source code just like you’d change any other list (or rather tree) data type.
However all this can be represented fully without parentheses — and this is possible with Guile using a reader extension without losing any of its power. This is realized, for example, in wisp — a language frontend for Guile: http://www.draketo.de/english/wisp http://www.draketo.de/english/wisp
It’s a full Scheme, but without the parentheses (behind the scenes it simply infers the parentheses, adds them and hands the result to the regular Scheme frontend in Guile).
Wisp is also standardized as Scheme Request For Implementation 119: https://srfi.schemers.org/srfi-119/srfi-119.html https://srfi.schemers.org/srfi-119/srfi-119.html
display "Hello World!" ↦ (display "Hello World!")
In short: I think this question is justified. But there are many people who start preferring parentheses when they get over the initial readability barrier.
- Slackwise 10y agoAs a simpler solution, making brackets a lighter color so they don't stand out as much. Works really well.
- amirouche 10y agoI use rainbow-delimiter mode in emacs, it of great help.
- branchly2 10y ago> The super advantage of Lisp (including Scheme): Its format for defining data is the same as for writing code, making macros a natural part of the syntax: You can change your source code just like you’d change any other list (or rather tree) data type. I've heard this repeatedly over the years, but the explanation unfortunately always stops right there. Could you please give an example of why you'd want to change your source code programatically? It's always assumed that the reader implicitly knows why this is a good and important thing. Perhaps a practical example showing (A) how this would work, (B) what the benefit is, and (C) how the added work in reasoning is worth that benefit. Note: I personally like the parentheses, as they group everything together so simply.
- davexunit 10y ago>Could you please give an example of why you'd want to change your source code programatically? To create new syntax and be your own language designer. This is what macro systems allow for. Here's a very contrived and simple example. Guile comes with no equivalent of the `++` operator that we know from C, C++, etc. So in the event that we have some imperative code that is mutating a counter, we'd have to write something like this: (define counter 0) ;; do some stuff... (set! counter (+ counter 1)) Quite a lot more typing! It would be especially annoying if we had many such counters. Normally, when we want to factorize code, we'd write a function, but there's a problem: We can't write a function that mutates any given variable. So, this wouldn't work: (define (++ n) (set! n (+ n 1))) (define counter 0) (++ counter) This is just mutating a local variable `n`, nothing happens to the variable `counter`, it's still 0. So what do we do? Instead of a function abstraction, we'll use a syntactic abstraction instead. Here is a macro that does what we want: (define-syntax-rule (++ var) (set! var (+ var 1))) (define counter-a 0) (define counter-b 0) (++ counter-a) (++ counter-b) (++ counter-a) Now `counter-a` is 2 and `counter-b` is 1. The `++` macro is a program that writes programs. It takes `(++ counter-a)` and expands it into the code `(set! counter-a (+ counter-a 1))`. The reason these syntactic abstractions are so easy to make is because of the homoiconic Lisp syntax. I hope this has made sense and is helpful. Moving on from this simple example, we can create entirely new languages that are embedded in Scheme if we wanted to, adding things that are too specific to a problem domain to ever be in the standard language's syntax but very useful for the problem we are trying to solve.
- WalterGR 10y ago