unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Re: bug#13077: guile: add repl-option for customized print
       [not found] <87hao21nte.fsf@gmail.com>
@ 2012-12-04  5:19 ` nalaginrut
  2012-12-04  5:34   ` Daniel Hartwig
       [not found]   ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg__21131.9749746055$1354599399$gmane$org@mail.gmail.com>
  0 siblings, 2 replies; 10+ 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] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
  2012-12-04  5:19 ` bug#13077: guile: add repl-option for customized print nalaginrut
@ 2012-12-04  5:34   ` Daniel Hartwig
  2012-12-04  6:30     ` nalaginrut
  2012-12-12  4:03     ` Nala Ginrut
       [not found]   ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg__21131.9749746055$1354599399$gmane$org@mail.gmail.com>
  1 sibling, 2 replies; 10+ 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] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
  2012-12-04  5:34   ` Daniel Hartwig
@ 2012-12-04  6:30     ` nalaginrut
  2012-12-04  6:34       ` Daniel Hartwig
  2012-12-12  4:03     ` Nala Ginrut
  1 sibling, 1 reply; 10+ 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] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
  2012-12-04  6:30     ` nalaginrut
@ 2012-12-04  6:34       ` Daniel Hartwig
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Hartwig @ 2012-12-04  6:34 UTC (permalink / raw
  To: nalaginrut; +Cc: guile-devel

On 4 December 2012 14:30, nalaginrut <nalaginrut@gmail.com> wrote:
> And I'll update it to repl-option version after ludo/andy accepts your
> patch.
>
> Or I should post it include your patch altogether? ;-)

Separate is easier to work with.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
       [not found]   ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg__21131.9749746055$1354599399$gmane$org@mail.gmail.com>
@ 2012-12-04  6:39     ` Thien-Thi Nguyen
  2012-12-04  7:36       ` Daniel Hartwig
  0 siblings, 1 reply; 10+ messages in thread
From: Thien-Thi Nguyen @ 2012-12-04  6:39 UTC (permalink / raw
  To: Daniel Hartwig; +Cc: guile-devel, 13077

[-- Attachment #1: Type: text/plain, Size: 650 bytes --]

() 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.

-- 
Thien-Thi Nguyen ..................................... GPG key: 4C807502
.                  NB: ttn at glug dot org is not me                   .
.                 (and has not been since 2007 or so)                  .
.                        ACCEPT NO SUBSTITUTES                         .
........... please send technical questions to mailing lists ...........

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
  2012-12-04  6:39     ` Thien-Thi Nguyen
@ 2012-12-04  7:36       ` Daniel Hartwig
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Hartwig @ 2012-12-04  7:36 UTC (permalink / raw
  To: Thien-Thi Nguyen; +Cc: guile-devel, 13077

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] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
  2012-12-04  5:34   ` Daniel Hartwig
  2012-12-04  6:30     ` nalaginrut
@ 2012-12-12  4:03     ` Nala Ginrut
  2012-12-12  5:00       ` Daniel Hartwig
  1 sibling, 1 reply; 10+ 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] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
  2012-12-12  4:03     ` Nala Ginrut
@ 2012-12-12  5:00       ` Daniel Hartwig
  2012-12-12  5:49         ` Nala Ginrut
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Hartwig @ 2012-12-12  5:00 UTC (permalink / raw
  To: Nala Ginrut; +Cc: guile-devel

[No need to Cc the bug report]

On 12 December 2012 12:03, Nala Ginrut <nalaginrut@gmail.com> wrote:
> Seems (fluid-ref *repl-stack*) is not a pair/list when REPL is just
> started?

Correction: is not a pair/list when /guile/ is just started.  The
program, guile, is not a REPL, that is only an optional component of
it.

You can't set REPL options before there is a REPL.  The rc file
(.guile) is applicable to all of guile, and read during initialization
which is before any REPL is created.

Try repl-default-option-set!.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
  2012-12-12  5:00       ` Daniel Hartwig
@ 2012-12-12  5:49         ` Nala Ginrut
       [not found]           ` <CAN3veRdDA-LwBhu7_Uthfj1h7HGzvFOPLoOtkoyd-MQOA+1Xug@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Nala Ginrut @ 2012-12-12  5:49 UTC (permalink / raw
  To: Daniel Hartwig; +Cc: guile-devel

On Wed, 2012-12-12 at 13:00 +0800, Daniel Hartwig wrote:
> [No need to Cc the bug report]
> 
> On 12 December 2012 12:03, Nala Ginrut <nalaginrut@gmail.com> wrote:
> > Seems (fluid-ref *repl-stack*) is not a pair/list when REPL is just
> > started?
> 
> Correction: is not a pair/list when /guile/ is just started.  The
> program, guile, is not a REPL, that is only an optional component of
> it.
> 
> You can't set REPL options before there is a REPL.  The rc file
> (.guile) is applicable to all of guile, and read during initialization
> which is before any REPL is created.
> 
> Try repl-default-option-set!.

repl-default-option-set! seems didn't make sense. How can I check the
REPL exist? My idea is to do that after I detected the REPL existed.

I believe people more like to activate the colored-REPL automatically
when ~/.guile is setup. Rather than call (activate-colorized) manually,
just like 'readline' module does.

Regards.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bug#13077: guile: add repl-option for customized print
       [not found]           ` <CAN3veRdDA-LwBhu7_Uthfj1h7HGzvFOPLoOtkoyd-MQOA+1Xug@mail.gmail.com>
@ 2012-12-12  6:03             ` Daniel Hartwig
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Hartwig @ 2012-12-12  6:03 UTC (permalink / raw
  To: Nala Ginrut, guile-devel

On 12 December 2012 14:01, Daniel Hartwig <mandyke@gmail.com> wrote:
> On 12 December 2012 13:49, Nala Ginrut <nalaginrut@gmail.com> wrote:
>> repl-default-option-set! seems didn't make sense.
>
> Works fine for me.
>
>>
>> I believe people more like to activate the colored-REPL automatically
>> when ~/.guile is setup. Rather than call (activate-colorized) manually,
>> just like 'readline' module does.
>
> Then you rather implement “repl-printer” akin to “repl-reader” used by
> the readline module.

… and perhaps that makes more sense than using a repl option, given
the symmetry between printer and reader.



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-12-12  6:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87hao21nte.fsf@gmail.com>
2012-12-04  5:19 ` bug#13077: guile: add repl-option for customized print nalaginrut
2012-12-04  5:34   ` Daniel Hartwig
2012-12-04  6:30     ` nalaginrut
2012-12-04  6:34       ` Daniel Hartwig
2012-12-12  4:03     ` Nala Ginrut
2012-12-12  5:00       ` Daniel Hartwig
2012-12-12  5:49         ` Nala Ginrut
     [not found]           ` <CAN3veRdDA-LwBhu7_Uthfj1h7HGzvFOPLoOtkoyd-MQOA+1Xug@mail.gmail.com>
2012-12-12  6:03             ` Daniel Hartwig
     [not found]   ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg__21131.9749746055$1354599399$gmane$org@mail.gmail.com>
2012-12-04  6:39     ` Thien-Thi Nguyen
2012-12-04  7:36       ` Daniel Hartwig

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).