edicl / cl-who

Yet another Lisp markup language
https://edicl.github.io/cl-who/
105 stars 26 forks source link

EVAL captures dynamic print-syntax #31

Closed frodef closed 3 years ago

frodef commented 3 years ago

When a WITH-HTML-OUTPUT is compiled with non-standard print syntax (e.g. print-base 16), that is somehow captured/closed over at compile-time such that even e.g. wrapping the form in WITH-STANDARD-IO-SYNTAX does not help. This is quite unexpected behaviour and also confusing. I'm guessing what happens is in CONVERT-ATTRIBUTES the CONSTANTP attributes are formatted with tilde A at compile-time.

I'd suggest making such compile-time constant folding optional (presumably it's a speed optimization feature?), and also wrapping it in a compile-time WITH-STANDARD-IO-SYNTAX.

stassats commented 3 years ago

Test cases, test cases!

frodef commented 3 years ago

Test-case:

(funcall (let ((print-base 16) (print-radix t)) (compile 'foo '(lambda () (cl-who:with-html-output-to-string (s) ((:foo :bar 123 :zap 124)))))))

=> ""

On Tue, Jan 12, 2021 at 3:00 PM Stas Boukarev notifications@github.com wrote:

Test cases, test cases!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/edicl/cl-who/issues/31#issuecomment-758673123, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACODFKLDJIHVDSIKQIMAELSZRIYPANCNFSM4V64LLPA .

-- Frode Fjeld

frodef commented 3 years ago

...and even this, even though the outer LET or WITH-STANDARD-IO-SYNTAX shouldn't be required:

(let ((*print-base* 10.) (*print-radix* nil))
  (funcall
     (let ((*print-base* 16) (*print-radix* t))
     (compile 'foo '(lambda ()
             (cl-who:with-html-output-to-string (s)
               ((:foo :bar 123 :zap 124))))))))

=> "<foo bar='#x7B' zap='#x7C'></foo>"
stassats commented 3 years ago

OK, that does happen, now you know not to do that.

frodef commented 3 years ago

While I don't want to come off as entitled or ungrateful for using software that I have not paid for in any way, I must say I find this an extremely pointless and unconstructive way to deal with a bug report, especially after having asked for test-cases.

Presumably you don't actually believe that I compile my software in the manner shown. Rather, I put quite some effort into constructing a self-contained form as a test-case that displays the bug precisely. This bug I originally encountered in a much more coincidental and "natural" manner, in an actual application and actual development environment. This is a bug that I believe is likely to bite many others, and which can be quite confusing to understand.

I'd be happy to provide a fix too, even though the fix is trivial (and probably better made by those already intimate with the code) once the bug is understood.

stassats commented 3 years ago

I see no bug, so no need to send fixes. Just don't use weird print bases.

frodef commented 3 years ago

"Just don't use weird print bases"?! I'm not sure what to say to that. Either you just don't understand the issue at all, and/or you are being incredibly short-sighted.

This is a severe bug, insofar as cl-who is intended to be a reasonably usable general Common Lisp library. Any application and system risks being bitten by this bug if any developer at any point "use weird print bases", something many people actually do.