3 ms·
The code for that calculator is generally not that bad, but it lacks clues what the symbols are. In Common Lisp there are conventions for example that +foo+ is
by lispm 4y ago
The code for that calculator is generally not that bad, but it lacks clues what the symbols are. In Common Lisp there are conventions for example that +foo+ is a constant, that WITH-SOMETHING is a scoping macro, etc.
It also uses longer function names and single letter variable names. That's a strange mix.
One problem with the code though is the layout/formatting. This is not what I would expect as a Lisp user.
I would expect to be able to see more block structure from the code layout:
(define (number->neatstring n)
(if (not (##flonum? n))
(number->string n)
(let* ((s (number->string
(fl/ (flfloor (fl+ (fl* (flo n) 1.0e10) 0.5))
1.0e10)))
(sl (string-length s))
(b (substring s 0 1))
(e (substring s (- sl 1) sl)))
(string-append (if (string=? b ".") "0" "")
(if (string=? e ".")
(substring s 0 (- sl 1))
s)))))
If I have a function call with 2 args I don't want:
(long-function-name long-expression-1
long-expression-2)
because that's what macros with a body would be formatted.
I would want either
(long-function-name
long-expression-1
long-expression-2)
or
(long-function-name long-expression-1
long-expression-2)
Both tell me that both expressions are on the same level syntactically and semantically: both are function arguments.
- kazinator 4y agoTXR Lisp: (defun neat-number-to-ten-digits (n) (fmt "~1,10a" n)) ;; all digits of integer rendered; prec digits of floating-point value. ;; floating point integer omits trailing decimal point. ;; leading decimal point is 0. not just . (defun neat-number (n prec) (fmt "~1,*a" prec n)) 5> (neat-number 1.12345 3) "1.12" 6> (neat-number 1.0 3) "1" 7> (neat-number 1 3) "1" 8> (neat-number 12334234234 3) "12334234234" 9> (neat-number 12334234234.9 3) "1.23e10"