4 ms·
> taught that lisp has no syntax Which is wrong. It's just that Lisp syntax looks and works a bit different. Especially there is a data syntax for s-expression
by lispm 10y ago
> taught that lisp has no syntax
Which is wrong. It's just that Lisp syntax looks and works a bit different. Especially there is a data syntax for s-expressions and the syntax for the programming language Lisp is defined on top of s-expressions.
> And that they should avoid the reader macro at all costs.
Common Lisp itself uses read macros for its implementation. Applications use them in various ways.
> In this example, though, what was the advantage of the special syntax?
Xappings were a central data structure in Connection Machine Lisp, thus it's not unusual that it had a printed representation.
- taeric 10y agoAgreed on your points. Especially that it has syntax. But look at the linked post upthread. I said "no" syntax, but that was me being admittedly lazy. Quote there was "Lisp is a language with little syntax". Which has me wondering why it has that general view with everyone. For the representation.. So this was not simply a literal syntax, but a serialization one. Which makes sense. And I can see why the serialization syntax is easily usable as a literal one.
- kazinator 10y agoGCC's C parser is a 550 kilobyte file that is almost 19000 lines long. The C++ one is over 1.1 megabytes long, and close to 39,000 lines. Github refuses to display it as code, only raw. Lisps don't have anything that even comes close.
- taeric 10y agoBut that is a different claim, isn't it? I would expect that the general parser for a CL implementation is also quite large. My question is why does the teaching often go that there is practically no syntax for lisp. Now, it is often followed quickly with "in lisp, you can write your own language." But then, those two thoughts are hard to justify next to each other. Again, just see this thread. The complaint is that there is not enough syntax in lisp. The argument appearing that you have to have another language to express some ideas. And again, I'm not even disagreeing with this claim. Just trying to understand why it has the foothold that it does. That you drop to lisp if you want to use no syntax.
- kazinator 10y agoJust checked an old clisp-2.32 source tree I have laying around on an old hard drive. The raw line count in the src/ directory over all .d and .lisp files is 212K. Compiler, CLOS, all in there. The io.d module (preprocessed C source) which contains the reader and printer, plus some other cruft, is 10K.
- taeric 10y agoJust wow. I would expect it to be smaller. But I am surprised it is that much smaller.
- lispm 10y agoSince many/most Lisp macros implement syntax, there can be a lot of syntax in Lisp, too. The parsing of the syntax is distributed over the macro definitions, sometimes with some help of the general macro mechanism. See for example the syntax which is implemented by macros like LOOP or ITERATE. The LOOP syntax is documented in the ANSI CL spec... http://www.lispworks.com/documentation/lw51/CLHS/Body/m_loop.htm http://www.lispworks.com/documentation/lw51/CLHS/Body/m_loop...
- kazinator 10y agoMacros do not have to deal with syntax at the level of "how does this sequence of tokens reshape into a tree". (Not usually; exceptions are easily contrived and exist in the wild.) Usually, the syntax is already parsed when it comes into a macro. E,g: (sentence-macro subject object verb) sentence-macro doesn't have guess what part of the utterance is the object and which is the verb. The verb is the third argument, and that is that. This is the case whether it is a single word, or a phrase. Though this is still syntax, it is parsed syntax. When we say that Lisp has no syntax, it means that it dosen't have that silly, counterproductive stuff naively imitated from natural languages which represents the tree in a way that requires mind-bending work to recover.
- taeric 10y agoYou should probably check out the LOOP macro sometime. Examples include: (loop for i from 0 to 10 for j from 10 downto 0 collect (cons i j)) That is a fully legit expression. So, if you consider LOOP contrived, then you have a point. It is a very useful and a very powerful macro, though. Not sure why it wouldn't count.
- kazinator 10y agoLOOP does speak to what you can do with macros. Obviously, a macro can interpret its arguments however it wants. You can implement a language that requires GLR (or worse). LOOP is also not universally loved in the Lisp world. It's fine if you don't need to extend it. Not only is it inherently inextensible (for no good reason), but it's hostile to wrapping. If you write a MYLOOP macro which passes most of its arguments to LOOP and adds a few clauses of its own (translated to LOOP syntax), you have to parse the LOOP syntax to see where your clauses are and in which order in relation to the standard ones. (Unless you do something hacky or ugly, like recognize your extensions by some delimiters, without regard for the surrounding syntax, so that they don't actually blend in.) LOOP is the only high level control construct I've ever seen anywhere in which you can achieve nonportable behaviors: because of the construct itself, not because of nonportable expressions plugged into it. The treatment of clause symbols as character strings, so that CL:FOR and MYPACKAGE:FOR can both head off a for clause is a design smell. LOOP should have been designed to use symbols in the CL package, so that if someone wants to use APPENDING, they nicely import that symbol or pick it up via :use. LOOP asks you to use different syntax for walking a vector and list, when the rest of Lisp has a sequences library that lets you use common functions for both. Supporting the specialized syntax is fine (just like the library also has list and vector specific things), but the lack of a generic sequence iterating clause shows a discord with the rest of the language. It didn't require much imagination to have, say a FOR x OVER <list-string-or-vec>. We can have a perfectly good Lisp dialect without any sort of mini-language parsing macro like LOOP. It illustrates what you can do with macros, not what is usually done with macros. Macros usually leverage their tree structure and destructuring not to do any parsing work, and focus on the transformation and its semantics.
- chubot 10y agoIf you think that's bad, just representing C++, not even parsing it, in Clang, takes 61K lines of headers! If you look at these files it's mostly declarations and one-line functions. It's not even doing anything. The lexers and parsers are a whole other story, certainly greater than 19K lines combined. ~/src/cfe-3.8.0.src/include/clang/AST$ wc -l *.h 2742 DeclObjC.h 2809 RecursiveASTVisitor.h 2927 DeclTemplate.h 3198 OpenMPClause.h 3249 DeclCXX.h 3800 Decl.h 4154 ExprCXX.h 4942 Expr.h 5723 Type.h 61525 total