sexp.lisp: Option to insert line breaks.
- Linguagem predominante
- Common Lisp
- Estrelas
- 34
- Forks
- 7
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
Instead of outputting everything on one line, it's be nice to leave some customization options to the users so that they can decide when to insert line breaks.
For instance:
```lisp
(export '*one-element-per-line*)
(defvar *one-element-per-line* nil
"If non-nil, print one element per line in sequence types.")
(defun maybe-newline (stream)
(when *one-element-per-line*
(write-char #\newline stream)))
(defmethod serialize-sexp-internal ((object sequence) stream serialization-state)
"Like the original `serialize-sexp-internal' but uses `*one-element-per-line* to "
(flet ((proper-sequence (length)
(let ((id (set-known-object serialization-state object)))
(write-string "(:SEQUENCE " stream)
(prin1 id stream)
(write-string " :CLASS " stream)
(print-symbol (etypecase object (list 'list) (vector 'vector)) stream)
(write-string " :SIZE " stream)
(prin1 length stream)
(unless (zerop length)
(write-string " :ELEMENTS (" stream)
(maybe-newline stream)
(map nil
#'(lambda (element)
(write-string " " stream)
(serialize-sexp-internal element stream serialization-state)
(maybe-newline stream))
object))
(write-string " ) )" stream)))
(improper-list ()
(let ((id (set-known-object serialization-state object)))
(write-string "(:CONS " stream)
(prin1 id stream)
(write-char #\Space stream)
(serialize-sexp-internal (car object) stream serialization-state)
(write-char #\Space stream)
(serialize-sexp-internal (cdr object) stream serialization-state)
(write-string " ) " stream))))
(let ((id (known-object-id serialization-state object)))
(if id
(progn
(write-string "(:REF . " stream)
(prin1 id stream)
(write-string ")" stream))
(multiple-value-bind (seq-type length) (sequence-type-and-length object)
(ecase seq-type
((:proper-sequence :proper-list) (proper-sequence length))
((:dotted-list :circular-list) (improper-list))))))))
```
The above function is like the original except for the `maybe-newline` calls.
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
The issue is about modifying sexp.lisp to add an option for line breaks in serialized output. Start by examining the existing serialize-sexp-internal method for sequences. The provided code snippet shows where to insert maybe-newline calls. Look at the surrounding code to understand the serialization-state and stream handling. Test changes by running any existing tests for serialization to ensure output remains correct.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- lua
- Domínio
- backend
- Tipo de issue
- Funcionalidade
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100