2 ms·
> Questions I find hard to answer for the above line is: how many args does "iter" have? It's obvious to me in a millisecond glance that docs and iter are call
by kazinator 10y ago
> Questions I find hard to answer for the above line is: how many args does "iter" have?
It's obvious to me in a millisecond glance that docs and iter are called with one argument.
For one thing, the snippet does not contain a single instance of a ) parenthesis being followed by a ( parenthesis. Also, none of the ) parentheses have any material between them. It's just (sym (sym (sym stuff ...))).
Only three trailing parens are required to close (docs; the other two are for something else.
If iter had additional arguments, it might be written like this:
(docs (iter (db.sort *game-collection* :all
:field "votes"
:asc nil)
(another-iter-arg)))
It is still obvious that docs has one arg, iter has two and that the :all :field material is under db.sort.
https://news.ycombinator.com/item?id=9229339 https://news.ycombinator.com/item?id=9229339
- alkonaut 10y agoAh, the arg-count-from-indentation makes sense with the concrete example, thanks. That said: if the code is neither correctly indented or has the parens correctly balanced - then one is in a pickle. It's easy to balance parens on correctly indented code, and it's trivial to indent correctly balanced code.
- junke 10y ago> That said: if the code is neither correctly indented or has the parens correctly balanced - then one is in a pickle. But you can format the code automatically, and check if all is good by looking at the shape of your code (indentation). If the amount is the same but you put elements in a strange location, like: (defun bar () (let ((a (foo)) (print (list a))))) Simply pretty-printing it with PPRINT will do: (DEFUN BAR () (LET ((A (FOO)) (PRINT (LIST A))) )) (C-c RET, aka. slime-expand-1-inplace, will work too). Indentation and parenthesis introduce a level of error checking by redundancy: the tools works on structured expressions, you look at indentation. Here above you can see that the body of the LET is empty, while there is a bogus binding in it. The above example is in practice quite rare. Most errors are easily spotted with paren highlighting. I use paredit, which makes structural editing easy (but which is not too rigid and allows me to make unstructured changes too). You generally don't have unbalanced parenthesis, and if you don't spot the bad syntax with indentation, the compiler has a chance to complain, too.