6 ms·
The DSL for string formatting certainly doesn't look simple. (format t "~{~@(~A~)~^ ~}, because ~{~A~^ ~} is easier!" llthw (cddr llthw))
by gre 12y ago
The DSL for string formatting certainly doesn't look simple.
(format t "~{~@(~A~)~^ ~}, because ~{~A~^ ~} is easier!" llthw (cddr llthw))
- gaigepr 12y agoI am only recently a lisp user but honestly, how is the format function far from: printf("something %s then %d finally %f!", "asd", 1, 1.2) As mentioned, there is a loop built into format. Since lisp also has a (list) function eg: (list 'a 'b 'c 1) I still don't see an argument beyond familiarity with the C style printf syntax for why format is bad/unreadable.
- wglb 12y agoThere is a loop embedded in the lisp version.
- mcosta 12y agoI do not understant it, but with changing ~ with % I can imagine what it does.
- ScottBurson 12y agoIt's complex because it's powerful. ~A is the most common directive; it simply prints an object. '~{...~}' (braces) iterates over a list, applying the directives within it to the list elements. Within that construct, '~^' exits if the last element of the list has been consumed; it's used here to keep the separating space from being printed after the last element. '~@(...~)' (parens) capitalizes words in the output of the directives it contains, downcasing the non-initial character of each word. So there's a lot more power here than in 'printf' control strings. If you find the more exotic notation unintuitive -- and you certainly wouldn't be alone -- you don't have to use it.
- gre 12y agoIt's just disingenuous to say that LISP has extremely simple syntax and then show the DSL for format, which is anything but LISPy or simple.
- CatMtKing 12y agoIt's disingenuous to claim a DSL is part of the language syntax. E.g. I would not consider the regex formatting specification as Python syntax. I mean, if we follow that line of thought, it's like saying Jinja is Python syntax.
- Avshalom 12y agoIf you're going to need to teach it for students to read and write programs in the wild than it's irrelevant whether it's 'part of the language syntax' or the ecosystem's syntax. 'Loop' is another one. Lisp as an idea has a simple syntax but Common Lisp isn't even close to that platonic ideal.
- ScottBurson 12y agoI don't know if it's disingenuous, but I'll agree that it may not be good marketing :-)