From maechler at stat.math.ethz.ch  Mon Apr 20 23:23:23 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Mon, 20 Apr 2009 23:23:23 +0200
Subject: [Rd] print.closure at the R level
In-Reply-To: <49ECDE2E.5060105@dbmail.com>
References: <49E9DFE5.7060501@dbmail.com> <49E9E25D.9070106@stats.uwo.ca>
	<49EA39F1.2010709@dbmail.com> <49EAF99E.9070703@dbmail.com>
	<49ECDE2E.5060105@dbmail.com>
Message-ID: <18924.59339.873021.630427@cmath-5.math.ethz.ch>

>>>>> "RF" == Romain Francois <romain.francois at dbmail.com>
>>>>>     on Mon, 20 Apr 2009 22:42:22 +0200 writes:

    RF> Hello,

    RF> Sorry if I have waisted any time of people truing this
    RF> patch. 

yes, you did waste (sic) ....
but thank you for the code suggestions anyway.

    RF> There was an issue with debugging (use of debug
    RF> and browser that caused an infinite recursion). I think
    RF> this is now fixed.

[ actually I had found even simpler bugs in it, e.g.
  you accidentally called C-level "print.function()" on "language",
  some may have been fixed by your new patch too, but others are  
  not {e.g., print() *must* return its argument !}
]

However, I've already changed your old patch too much
(notably by using *our* C coding standards) to want to look at
your new patch in detail.

If you want we can communicate off-list about this, 
tomorrow...

Martin Maechler, ETH Zurich


    RF> At the R level, I have now this :

    >> print.function
    RF> function (x, useSource = TRUE, ...)  {
    RF> invisible(.Internal(print.function(x, useSource, ...)))
    RF> } <environment: namespace:base>

    RF> and the PrintValueRec dispatches like this at the C
    RF> level:

    RF>     case LANGSXP: PrintLanguage(s, FALSE) ; break; case
    RF> CLOSXP: { SEXP call; PROTECT( call =
    RF> lang2(install("print.function"), s)); eval(call,env);
    RF> UNPROTECT(1); break; }

    RF> so that LANGSXP are printed using the PrintLanguage
    RF> function and CLOSXP are printed using the R function
    RF> print.function which in turns calls the PrintClosure
    RF> function (unless it is masked in R)

    RF> Romain


    RF> Romain Francois wrote:
    >> Yesterday's patch did not print the attributes. This one
    >> seems fine:
    >> 
    >> > f <- function(){} > attr( f, "yada" ) <- function( )
    >> "lobster bisk" > f function(){} attr(,"yada") function( )
    >> "lobster bisk"
    >> 
    >> Romain
    >> 
    >> Romain Francois wrote:
    >>> Duncan Murdoch wrote:
    >>>> On 18/04/2009 10:12 AM, Romain Francois wrote:
    >>>>> Hello,
    >>>>> 
    >>>>> Could the code that auto prints a function/closure be
    >>>>> extracted from print.c so that there would be a
    >>>>> print.closure function.  I would like to be able to
    >>>>> mask a print.closure function so that I have a custom
    >>>>> auto-print. One reason for that is I plan to have
    >>>>> syntax highlighting within the R console.
    >>>> 
    >>>> The class of a closure is "function", so you'd want the
    >>>> method to be print.function.  Currently that doesn't
    >>>> work for auto printing, so your suggestion is still
    >>>> interesting.  (I'm not sure why auto printing is
    >>>> special here...)
    >>>> 
    >>>> Duncan Murdoch
    >>> The attached patch implements exposing the
    >>> print.function at the R level.
    >>> 
    >>> Romain
    >>> 
    >>> ------------------------------------------------------------------------
    >>> 
    >>> ______________________________________________
    >>> R-devel at r-project.org mailing list
    >>> https://stat.ethz.ch/mailman/listinfo/r-devel
    >> 
    >> 
    >> ------------------------------------------------------------------------
    >> 
    >> ______________________________________________
    >> R-devel at r-project.org mailing list
    >> https://stat.ethz.ch/mailman/listinfo/r-devel


    RF> -- Romain Francois Independent R Consultant +33(0) 6 28
    RF> 91 30 30 http://romainfrancois.blog.free.fr



[Rd] print.closure at the R level
Martin Maechler