I've noticed that ,doc fcollect
produces weirdly indented documentation:
>> ,doc fcollect
(fcollect iter-tbl value-expr ...)
Return a sequential table made by advancing a range as specified by
for, and evaluating an expression that returns values to be inserted
sequentially into the table. This can be thought of as a range
comprehension. If the body evaluates to nil that element is omitted.
For example,
(fcollect [i 1 10 2]
(when (not= i 3)
(* i i)))
returns
[1 25 49 81]
Supports an &into clause after the range to put results in an existing table.
Supports early termination with an &until clause.
>>
This happens both in an ordinary terminal, and in Emacs repls.
This happens to a lot of forms, but not for all of them:
>> ,doc lambda
(lambda ...)
Function literal with nil-checked arguments.
Like `fn`, but will throw an exception if a declared argument is passed in as
nil, unless that argument's name begins with a question mark.
>> ,doc fn
(fn name? args docstring? ...)
Function syntax. May optionally include a name and docstring or a metadata table.
If a name is provided, the function will be bound in the current scope.
When called with the wrong number of args, excess args will be discarded
and lacking args will be nil, use lambda for arity-checked functions.
>>
Upon further inspection it turned out that the reason for that is that fennel.lua
has these macros stored in a giant string, and that indentation is preserved when this string is evaluated, adding additional two spaces.
Specials, such as fn
on the other hand, store their documentation in a spearate place, and it has the correct indentation.
I looked at this today, and I think the cleanest fix will be to change
(eval (embed-source ...) ...)With a macro that loads the macros source, precompiles it within compiler scope with
:env _COMPILER
, emits the lua code as a string, and loads it in runtime in place ofeval
, using the newly created compiler env.Which sounds super confusing, but it should prevent the need for the bracket string and remove the indent. Bonus point, it'll save a little initialization time as fennel wouldn't have to compile parts of itself at startup.
This comes from the fact that the bootstrap compiler loading
src/fennel/macros.fnl
and dumping it into fennel.lua adds one layer of two-space indents, and then compiling the embedded string of macro code into lua again at boot adds another layer of two-space indents. For some reason the:indent
setting in compiler opts at both these points gets ignored.The ideal fix would be to get it to stop ignoring
:indent
.