I understand that the option (repl-default-option-set! 'print ...) is to be used and i've tried so in many variations, i grokked the idea behind customizing the prompt (repl-default-option-set! 'promp ">>>") but can't seem to get the print aspect to work, ideally i would like to get rid of the increasing $num print that happens before the evalutations result
I'm using guile 3 and trying to customize the "print" aspect of the repl
257 Views Asked by Alexander Castillo AtThere are 4 best solutions below
On
You actually have an option to modify the printer by overriding write and display GOOPS generalized methods (this is done e.g. in python-on-guile repository https://gitlab.com/python-on-guile/python-on-guile). You can also overwrite the standard printer function entirely if you want total control, here is a simplified example (you need to be able to handle a port argument as well), this example only work for terminals that understand unix terminal escape sequence and is a bit hacky, you can find escape sequences at, https://man7.org/linux/man-pages/man4/console_codes.4.html
Add this to your .guile file
(use-modules (system repl common))
(define old-write (@ (guile) write))
(define (my-write . x)
;; reverse line feed
(display (list->string '(#\Escape #\M)))
;; some other text
(format #t "~%And the result is ...~%")
(apply old-write x))
(repl-default-option-set! 'print
(lambda (repl obj)
(my-write obj)
(newline)))
Then a shell interaction in a unix escape terminal can look like
scheme@(guile-user)> (values 1 2)
And the result is ...
1
And the result is ...
2
On
You can change the options on the current repl with repl-option-set!. For example (repl-option-set! (car (fluid-ref *repl-stack*)) 'print p) will set the print function on the current repl. repl-option-set! and *repl-stack* are undocumented, but I don't think they're going anywhere. You should still use repl-default-option-set! to configure future repls, such as in ~/.guile.
The answer does indeed seem to be 'write your own REPL', which is extremely depressing.
Given:
Then two things happen:
So this doesn't work because you're setting some default option but the existing REPL has already chosen its printer. If you convince the system to start a new REPL, for instance by getting into a break loop, you get this:
So the print function is indeed printing
here, but that happens after the annoying$7 =thing (which I know has some purpose).So, well, it looks like alinsoar's comment is correct, sadly: the REPL is customisable but ... not enough.