* bug#13077: guile: add repl-option for customized print
@ 2012-12-04 3:46 Daniel Hartwig
2012-12-04 5:19 ` nalaginrut
[not found] ` <1354598358.25329.4.camel@Renee-desktop.suse>
0 siblings, 2 replies; 8+ messages in thread
From: Daniel Hartwig @ 2012-12-04 3:46 UTC (permalink / raw)
To: 13077; +Cc: nalaginrut
[-- Attachment #1: Type: text/plain, Size: 856 bytes --]
Package: guile
Severity: wishlist
Tags: patch
X-Debbugs-CC: nalaginrut <nalaginrut@gmail.com>
Dear maintainer
The attached patch adds a new repl-option to set a custom print
procedure.
--
scheme@(guile-user)> (use-modules (srfi srfi-1))
scheme@(guile-user)> (iota 20)
$1 = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
scheme@(guile-user)> (define (repl-print* repl val)
(if (not (eq? val *unspecified*))
(begin
(run-hook before-print-hook val)
(format #t "~20@y" val)
(newline))))
scheme@(guile-user)> (use-modules (system repl common))
scheme@(guile-user)> (repl-option-set! (car (fluid-ref *repl-stack*)) 'print repl-print*)
scheme@(guile-user)> (iota 20)
$2 = (0 1 2 3 4 5 6 7 …)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-repl-add-repl-option-for-customized-print.patch --]
[-- Type: text/x-diff, Size: 3033 bytes --]
From b0cadcb69a12a4ed2a205f4854af41bf926da20b Mon Sep 17 00:00:00 2001
From: Daniel Hartwig <mandyke@gmail.com>
Date: Tue, 4 Dec 2012 11:41:35 +0800
Subject: [PATCH] repl: add repl-option for customized print
* module/system/repl/common.scm (repl-default-options)
(repl-print): Add option to use customized print procedure.
* doc/ref/scheme-using.texi (REPL Commands): Update.
---
doc/ref/scheme-using.texi | 4 ++++
module/system/repl/common.scm | 26 +++++++++++++++++---------
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/doc/ref/scheme-using.texi b/doc/ref/scheme-using.texi
index 7eb84de..4f9e6db 100644
--- a/doc/ref/scheme-using.texi
+++ b/doc/ref/scheme-using.texi
@@ -445,6 +445,10 @@ choice is available. Off by default (indicating compilation).
@item prompt
A customized REPL prompt. @code{#f} by default, indicating the default
prompt.
+@item print
+A procedure of two arguments used to print the result of evaluating each
+expression. The arguments are the current REPL and the value to print.
+By default, @code{#f}, to use the default procedure.
@item value-history
Whether value history is on or not. @xref{Value History}.
@item on-error
diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm
index 346ba99..fd41b09 100644
--- a/module/system/repl/common.scm
+++ b/module/system/repl/common.scm
@@ -119,6 +119,11 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
((thunk? prompt) (lambda (repl) (prompt)))
((procedure? prompt) prompt)
(else (error "Invalid prompt" prompt)))))
+ (print #f ,(lambda (print)
+ (cond
+ ((not print) #f)
+ ((procedure? print) print)
+ (else (error "Invalid print procedure" print)))))
(value-history
,(value-history-enabled?)
,(lambda (x)
@@ -206,15 +211,18 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
(% (thunk))))
(define (repl-print repl val)
- (if (not (eq? val *unspecified*))
- (begin
- (run-hook before-print-hook val)
- ;; The result of an evaluation is representable in scheme, and
- ;; should be printed with the generic printer, `write'. The
- ;; language-printer is something else: it prints expressions of
- ;; a given language, not the result of evaluation.
- (write val)
- (newline))))
+ (cond
+ ((repl-option-ref repl 'print)
+ => (lambda (print) (print repl val)))
+ ((not (eq? val *unspecified*))
+ (begin
+ (run-hook before-print-hook val)
+ ;; The result of an evaluation is representable in scheme, and
+ ;; should be printed with the generic printer, `write'. The
+ ;; language-printer is something else: it prints expressions of
+ ;; a given language, not the result of evaluation.
+ (write val)
+ (newline)))))
(define (repl-option-ref repl key)
(cadr (or (assq key (repl-options repl))
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* bug#13077: guile: add repl-option for customized print
2012-12-04 3:46 bug#13077: guile: add repl-option for customized print Daniel Hartwig
@ 2012-12-04 5:19 ` nalaginrut
[not found] ` <1354598358.25329.4.camel@Renee-desktop.suse>
1 sibling, 0 replies; 8+ messages in thread
From: nalaginrut @ 2012-12-04 5:19 UTC (permalink / raw)
To: Daniel Hartwig, guile-devel; +Cc: 13077
Hi Daniel!
I believe this patch simplified my work, and 'colorized' module has been
finished, I'm testing and debugging.
I'll post it when it's all done.
Thanks!
On Tue, 2012-12-04 at 11:46 +0800, Daniel Hartwig wrote:
> Package: guile
> Severity: wishlist
> Tags: patch
> X-Debbugs-CC: nalaginrut <nalaginrut@gmail.com>
>
> Dear maintainer
>
> The attached patch adds a new repl-option to set a custom print
> procedure.
>
> --
> scheme@(guile-user)> (use-modules (srfi srfi-1))
> scheme@(guile-user)> (iota 20)
> $1 = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
> scheme@(guile-user)> (define (repl-print* repl val)
> (if (not (eq? val *unspecified*))
> (begin
> (run-hook before-print-hook val)
> (format #t "~20@y" val)
> (newline))))
> scheme@(guile-user)> (use-modules (system repl common))
> scheme@(guile-user)> (repl-option-set! (car (fluid-ref *repl-stack*)) 'print repl-print*)
> scheme@(guile-user)> (iota 20)
> $2 = (0 1 2 3 4 5 6 7 …)
> differences between files attachment
> (0001-repl-add-repl-option-for-customized-print.patch)
> From b0cadcb69a12a4ed2a205f4854af41bf926da20b Mon Sep 17 00:00:00 2001
> From: Daniel Hartwig <mandyke@gmail.com>
> Date: Tue, 4 Dec 2012 11:41:35 +0800
> Subject: [PATCH] repl: add repl-option for customized print
>
> * module/system/repl/common.scm (repl-default-options)
> (repl-print): Add option to use customized print procedure.
> * doc/ref/scheme-using.texi (REPL Commands): Update.
> ---
> doc/ref/scheme-using.texi | 4 ++++
> module/system/repl/common.scm | 26 +++++++++++++++++---------
> 2 files changed, 21 insertions(+), 9 deletions(-)
>
> diff --git a/doc/ref/scheme-using.texi b/doc/ref/scheme-using.texi
> index 7eb84de..4f9e6db 100644
> --- a/doc/ref/scheme-using.texi
> +++ b/doc/ref/scheme-using.texi
> @@ -445,6 +445,10 @@ choice is available. Off by default (indicating compilation).
> @item prompt
> A customized REPL prompt. @code{#f} by default, indicating the default
> prompt.
> +@item print
> +A procedure of two arguments used to print the result of evaluating each
> +expression. The arguments are the current REPL and the value to print.
> +By default, @code{#f}, to use the default procedure.
> @item value-history
> Whether value history is on or not. @xref{Value History}.
> @item on-error
> diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm
> index 346ba99..fd41b09 100644
> --- a/module/system/repl/common.scm
> +++ b/module/system/repl/common.scm
> @@ -119,6 +119,11 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
> ((thunk? prompt) (lambda (repl) (prompt)))
> ((procedure? prompt) prompt)
> (else (error "Invalid prompt" prompt)))))
> + (print #f ,(lambda (print)
> + (cond
> + ((not print) #f)
> + ((procedure? print) print)
> + (else (error "Invalid print procedure" print)))))
> (value-history
> ,(value-history-enabled?)
> ,(lambda (x)
> @@ -206,15 +211,18 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
> (% (thunk))))
>
> (define (repl-print repl val)
> - (if (not (eq? val *unspecified*))
> - (begin
> - (run-hook before-print-hook val)
> - ;; The result of an evaluation is representable in scheme, and
> - ;; should be printed with the generic printer, `write'. The
> - ;; language-printer is something else: it prints expressions of
> - ;; a given language, not the result of evaluation.
> - (write val)
> - (newline))))
> + (cond
> + ((repl-option-ref repl 'print)
> + => (lambda (print) (print repl val)))
> + ((not (eq? val *unspecified*))
> + (begin
> + (run-hook before-print-hook val)
> + ;; The result of an evaluation is representable in scheme, and
> + ;; should be printed with the generic printer, `write'. The
> + ;; language-printer is something else: it prints expressions of
> + ;; a given language, not the result of evaluation.
> + (write val)
> + (newline)))))
>
> (define (repl-option-ref repl key)
> (cadr (or (assq key (repl-options repl))
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#13077: guile: add repl-option for customized print
[not found] ` <1354598358.25329.4.camel@Renee-desktop.suse>
@ 2012-12-04 5:34 ` Daniel Hartwig
[not found] ` <87lides4mq.fsf@zigzag.favinet>
` (2 more replies)
[not found] ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg@mail.gmail.com>
1 sibling, 3 replies; 8+ messages in thread
From: Daniel Hartwig @ 2012-12-04 5:34 UTC (permalink / raw)
To: nalaginrut; +Cc: 13077, guile-devel
[-- Attachment #1: Type: text/plain, Size: 820 bytes --]
On 4 December 2012 13:19, nalaginrut <nalaginrut@gmail.com> wrote:
> Hi Daniel!
> I believe this patch simplified my work, and 'colorized' module has been
> finished, I'm testing and debugging.
> I'll post it when it's all done.
Glad to hear it.
Attached is an alternate patch that handles before-print-hook and
*unspecified* outside of the custom print procedure, to avoid the need
for boilerplate there.
--
scheme@(guile-user)> (define (repl-print* repl val)
(format #t "~20@y" val)
(newline))
scheme@(guile-user)> (use-modules (system repl common))
scheme@(guile-user)> (repl-option-set! (car (fluid-ref *repl-stack*))
'print repl-print*)
scheme@(guile-user)> (use-modules (srfi srfi-1))
scheme@(guile-user)> (iota 20)
$1 = (0 1 2 3 4 5 6 7 …)
[-- Attachment #2: 0001-repl-add-repl-option-for-customized-print.alt.patch --]
[-- Type: application/octet-stream, Size: 2948 bytes --]
From 2251a259058524fbe631fd287c95b43882227f79 Mon Sep 17 00:00:00 2001
From: Daniel Hartwig <mandyke@gmail.com>
Date: Tue, 4 Dec 2012 11:41:35 +0800
Subject: [PATCH] repl: add repl-option for customized print
* module/system/repl/common.scm (repl-default-options)
(repl-print): Add option to use customized print procedure.
* doc/ref/scheme-using.texi (REPL Commands): Update.
---
doc/ref/scheme-using.texi | 4 ++++
module/system/repl/common.scm | 21 +++++++++++++++------
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/doc/ref/scheme-using.texi b/doc/ref/scheme-using.texi
index 7eb84de..4f9e6db 100644
--- a/doc/ref/scheme-using.texi
+++ b/doc/ref/scheme-using.texi
@@ -445,6 +445,10 @@ choice is available. Off by default (indicating compilation).
@item prompt
A customized REPL prompt. @code{#f} by default, indicating the default
prompt.
+@item print
+A procedure of two arguments used to print the result of evaluating each
+expression. The arguments are the current REPL and the value to print.
+By default, @code{#f}, to use the default procedure.
@item value-history
Whether value history is on or not. @xref{Value History}.
@item on-error
diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm
index 346ba99..3f3e785 100644
--- a/module/system/repl/common.scm
+++ b/module/system/repl/common.scm
@@ -119,6 +119,11 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
((thunk? prompt) (lambda (repl) (prompt)))
((procedure? prompt) prompt)
(else (error "Invalid prompt" prompt)))))
+ (print #f ,(lambda (print)
+ (cond
+ ((not print) #f)
+ ((procedure? print) print)
+ (else (error "Invalid print procedure" print)))))
(value-history
,(value-history-enabled?)
,(lambda (x)
@@ -209,12 +214,16 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
(if (not (eq? val *unspecified*))
(begin
(run-hook before-print-hook val)
- ;; The result of an evaluation is representable in scheme, and
- ;; should be printed with the generic printer, `write'. The
- ;; language-printer is something else: it prints expressions of
- ;; a given language, not the result of evaluation.
- (write val)
- (newline))))
+ (cond
+ ((repl-option-ref repl 'print)
+ => (lambda (print) (print repl val)))
+ (else
+ ;; The result of an evaluation is representable in scheme, and
+ ;; should be printed with the generic printer, `write'. The
+ ;; language-printer is something else: it prints expressions of
+ ;; a given language, not the result of evaluation.
+ (write val)
+ (newline))))))
(define (repl-option-ref repl key)
(cadr (or (assq key (repl-options repl))
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* bug#13077: guile: add repl-option for customized print
[not found] ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg@mail.gmail.com>
@ 2012-12-04 6:30 ` nalaginrut
2012-12-12 4:03 ` Nala Ginrut
1 sibling, 0 replies; 8+ messages in thread
From: nalaginrut @ 2012-12-04 6:30 UTC (permalink / raw)
To: Daniel Hartwig; +Cc: 13077, guile-devel
I'll post my original guile-colorized which uses 'before-print-hook' to
guile-dev. Though I've already tested it, I wish all folks test it for
me.
And I'll update it to repl-option version after ludo/andy accepts your
patch.
Or I should post it include your patch altogether? ;-)
On Tue, 2012-12-04 at 13:34 +0800, Daniel Hartwig wrote:
> On 4 December 2012 13:19, nalaginrut <nalaginrut@gmail.com> wrote:
> > Hi Daniel!
> > I believe this patch simplified my work, and 'colorized' module has been
> > finished, I'm testing and debugging.
> > I'll post it when it's all done.
>
> Glad to hear it.
>
> Attached is an alternate patch that handles before-print-hook and
> *unspecified* outside of the custom print procedure, to avoid the need
> for boilerplate there.
>
> --
> scheme@(guile-user)> (define (repl-print* repl val)
> (format #t "~20@y" val)
> (newline))
> scheme@(guile-user)> (use-modules (system repl common))
> scheme@(guile-user)> (repl-option-set! (car (fluid-ref *repl-stack*))
> 'print repl-print*)
> scheme@(guile-user)> (use-modules (srfi srfi-1))
> scheme@(guile-user)> (iota 20)
> $1 = (0 1 2 3 4 5 6 7 …)
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#13077: guile: add repl-option for customized print
[not found] ` <87lides4mq.fsf@zigzag.favinet>
@ 2012-12-04 7:36 ` Daniel Hartwig
0 siblings, 0 replies; 8+ messages in thread
From: Daniel Hartwig @ 2012-12-04 7:36 UTC (permalink / raw)
To: Thien-Thi Nguyen; +Cc: nalaginrut, 13077, guile-devel
On 4 December 2012 14:39, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
> () Daniel Hartwig <mandyke@gmail.com>
> () Tue, 4 Dec 2012 13:34:52 +0800
>
> patch that handles [...] *unspecified*
>
> Can ‘unspecified?’ (the procedure) be used? I seem to recall people
> wanting to avoid using ‘*unspecified*’ (the unique object) a while back.
Could do. Though the existing code uses *unspecified*, and changing
would be unrelated to the purpose of this patch.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#13077: guile: add repl-option for customized print
2012-12-04 5:34 ` Daniel Hartwig
[not found] ` <87lides4mq.fsf@zigzag.favinet>
@ 2012-12-10 22:25 ` Ludovic Courtès
2012-12-10 22:26 ` Ludovic Courtès
2 siblings, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2012-12-10 22:25 UTC (permalink / raw)
To: 13077
Hi Daniel,
Daniel Hartwig <mandyke@gmail.com> skribis:
> scheme@(guile-user)> (define (repl-print* repl val)
> (format #t "~20@y" val)
> (newline))
> scheme@(guile-user)> (use-modules (system repl common))
> scheme@(guile-user)> (repl-option-set! (car (fluid-ref *repl-stack*))
> 'print repl-print*)
> scheme@(guile-user)> (use-modules (srfi srfi-1))
> scheme@(guile-user)> (iota 20)
> $1 = (0 1 2 3 4 5 6 7 …)
Nice.
> From 2251a259058524fbe631fd287c95b43882227f79 Mon Sep 17 00:00:00 2001
> From: Daniel Hartwig <mandyke@gmail.com>
> Date: Tue, 4 Dec 2012 11:41:35 +0800
> Subject: [PATCH] repl: add repl-option for customized print
>
> * module/system/repl/common.scm (repl-default-options)
> (repl-print): Add option to use customized print procedure.
> * doc/ref/scheme-using.texi (REPL Commands): Update.
Applied, thanks!
Ludo’.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#13077: guile: add repl-option for customized print
2012-12-04 5:34 ` Daniel Hartwig
[not found] ` <87lides4mq.fsf@zigzag.favinet>
2012-12-10 22:25 ` Ludovic Courtès
@ 2012-12-10 22:26 ` Ludovic Courtès
2 siblings, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2012-12-10 22:26 UTC (permalink / raw)
To: 13077-done
Hi Daniel,
Daniel Hartwig <mandyke@gmail.com> skribis:
> scheme@(guile-user)> (define (repl-print* repl val)
> (format #t "~20@y" val)
> (newline))
> scheme@(guile-user)> (use-modules (system repl common))
> scheme@(guile-user)> (repl-option-set! (car (fluid-ref *repl-stack*))
> 'print repl-print*)
> scheme@(guile-user)> (use-modules (srfi srfi-1))
> scheme@(guile-user)> (iota 20)
> $1 = (0 1 2 3 4 5 6 7 …)
Nice.
> From 2251a259058524fbe631fd287c95b43882227f79 Mon Sep 17 00:00:00 2001
> From: Daniel Hartwig <mandyke@gmail.com>
> Date: Tue, 4 Dec 2012 11:41:35 +0800
> Subject: [PATCH] repl: add repl-option for customized print
>
> * module/system/repl/common.scm (repl-default-options)
> (repl-print): Add option to use customized print procedure.
> * doc/ref/scheme-using.texi (REPL Commands): Update.
Applied, thanks!
Ludo’.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#13077: guile: add repl-option for customized print
[not found] ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg@mail.gmail.com>
2012-12-04 6:30 ` nalaginrut
@ 2012-12-12 4:03 ` Nala Ginrut
1 sibling, 0 replies; 8+ messages in thread
From: Nala Ginrut @ 2012-12-12 4:03 UTC (permalink / raw)
To: Daniel Hartwig; +Cc: 13077, guile-devel
hi Daniel!
Custom color-scheme is done now! ;-D
But we have a problem... :-(
It's OK to test this code in the REPL:
--------------------cut-------------------
(use-modules (ice-9 colorized))
(add-color-scheme!
`((,(lambda (data) (and (number? data) (> data 10000)))
MY-LONG-NUM ,color-it (RED))))
(activate-colorized)
--------------------end-------------------
But when I put these lines into our ~/.guile, it throw error:
----------------err msg----------------
In /usr/local/share/guile/2.0/ice-9/colorized.scm:
31: 0 [activate-colorized]
/usr/local/share/guile/2.0/ice-9/colorized.scm:31:20: In procedure
activate-colorized:
/usr/local/share/guile/2.0/ice-9/colorized.scm:31:20: In procedure car:
Wrong type argument in position 1 (expecting pair): ()
------------------end------------------
Seems (fluid-ref *repl-stack*) is not a pair/list when REPL is just
started?
Please checkout here:
https://github.com/NalaGinrut/guile-colorized/blob/upstream/ice-9/colorized.scm#L31
Thanks!
On Tue, 2012-12-04 at 13:34 +0800, Daniel Hartwig wrote:
> On 4 December 2012 13:19, nalaginrut <nalaginrut@gmail.com> wrote:
> > Hi Daniel!
> > I believe this patch simplified my work, and 'colorized' module has been
> > finished, I'm testing and debugging.
> > I'll post it when it's all done.
>
> Glad to hear it.
>
> Attached is an alternate patch that handles before-print-hook and
> *unspecified* outside of the custom print procedure, to avoid the need
> for boilerplate there.
>
> --
> scheme@(guile-user)> (define (repl-print* repl val)
> (format #t "~20@y" val)
> (newline))
> scheme@(guile-user)> (use-modules (system repl common))
> scheme@(guile-user)> (repl-option-set! (car (fluid-ref *repl-stack*))
> 'print repl-print*)
> scheme@(guile-user)> (use-modules (srfi srfi-1))
> scheme@(guile-user)> (iota 20)
> $1 = (0 1 2 3 4 5 6 7 …)
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-12-12 4:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-04 3:46 bug#13077: guile: add repl-option for customized print Daniel Hartwig
2012-12-04 5:19 ` nalaginrut
[not found] ` <1354598358.25329.4.camel@Renee-desktop.suse>
2012-12-04 5:34 ` Daniel Hartwig
[not found] ` <87lides4mq.fsf@zigzag.favinet>
2012-12-04 7:36 ` Daniel Hartwig
2012-12-10 22:25 ` Ludovic Courtès
2012-12-10 22:26 ` Ludovic Courtès
[not found] ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg@mail.gmail.com>
2012-12-04 6:30 ` nalaginrut
2012-12-12 4:03 ` Nala Ginrut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).