From 0a39878841e911832a3aa3024cc1a8880e4f3ef8 Mon Sep 17 00:00:00 2001 From: Thomas Mailund Date: Thu, 20 Dec 2018 09:47:21 +0100 Subject: [PATCH] preparing for new release... --- NEWS.md | 7 ++++++- R/constructors.R | 2 +- cran-comments.md | 24 +++------------------- man/case_trfunc.Rd | 23 ++++++++------------- vignettes/getting-started-with-pmatch-.Rmd | 4 ++-- 5 files changed, 21 insertions(+), 39 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0a18f0d..445c64c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# pmatch 0.1.5 + + * Compatibility with rlang 0.3.0 + * Removed `cases` function (use `case_func` instead, it is much faster). + # pmatch 0.1.4 * New constructor code. This gives an substantial speedup when generating objects. @@ -11,7 +16,7 @@ # pmatch 0.1.3 * Formula syntax in cases as an alternative: cases(f(x), foo ~ bar, baz ~ qux). - This is easier to get to static code checkes such as lintr and through the + This is easier to get to static code checks such as lintr and through the byte compiler that can complain about "assignments" to literals. * bind[x,y,z] <- 1:3 syntax for binding variables. * transformation function transform_cases_function for modifying a function diff --git a/R/constructors.R b/R/constructors.R index 13aa026..bda8c5e 100644 --- a/R/constructors.R +++ b/R/constructors.R @@ -103,7 +103,7 @@ process_constructor_function <- function(constructor, data_type_name, env) { process_constructor_constant <- function(constructor, data_type_name, env) { constructor_name <- rlang::as_string(constructor) constructor_object <- structure( - NA, # FIXME: should this be list() ? + NA, constructor_constant = constructor_name, class = data_type_name ) diff --git a/cran-comments.md b/cran-comments.md index 953a800..a3fc7f7 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,35 +1,17 @@ - - # Update to 0.1.5 - * New constructor code. This gives an substantial speedup when generating objects. - * Added `case_func` as a much faster replacement for using the `cases` function. - * Removed `cases` (now that the faster `case_func` provides the same functionality). - * Suggests `ggraph` and `tidygraph` for vignettes - * Fixed a rewrite bug when using qualified names. - * Uses `foolbox` for a safer rewrite function. + * Compatibility with rlang 0.3.0. + * Removed `cases` function (`case_func` and `case_trfunc` replace it). ## Test environments * local OS X (Mojave) install, R 3.5.1 * ubuntu 14.04 (on travis-ci), R 3.3, 3.4, 3.5 -* win-builder (devel) +* win-builder (devel and release) * RHub: - - Windows Server 2008 R2 SP1, R-devel, 32/64 bit - - Windows Server 2008 R2 SP1, R-release, 32/64 bit - - CentOS 6, stock R from EPEL - - Ubuntu Linux 16.04 LTS, R-release, GCC - - Fedora Linux, R-devel, clang, gfortran - - Fedora Linux, R-devel, GCC - - Debian Linux, R-release, GCC - - macOS 10.11 El Capitan, R-release (experimental) - On Windows and Fedora, I get a Pandoc warning because - it cannot find the README badges. Other than that, the - checks pass. - ## R CMD check results 0 errors | 0 warnings | 0 notes diff --git a/man/case_trfunc.Rd b/man/case_trfunc.Rd index 786454c..3e70176 100644 --- a/man/case_trfunc.Rd +++ b/man/case_trfunc.Rd @@ -27,32 +27,27 @@ pattern is associated with. During matching, any symbol that is not quasi-quoted will be considered a variable, and matching values will be bound to such variables and be available when an expression is evaluated. -Unlike the \code{\link{case_func}} function, you cannot use this function -to define pattern matching functions that are not tail recursive. Furthermore, -you must use \code{\link{Recall}} for recursive calls. +This function works like \code{\link{case_func}} but implements the "tail-recursion +optimisation", which means that it replaces tail-recursive calls with reassignment +to local variables and looping. Since the scoping rules are different between +recursive calls and loops, you cannot use closures with this transformation +unless you take special care to bind all local values explicitly. -Functions created with \code{case_trfunc} do not support the \code{..} operator, -but you can always create constructors for fixed-number tuples, e.g. - -\code{ -tuples := ..(first, second) | ...(first, second, third) -} - -Be careful not to use \code{.} here, if you use dot as a generic -variable. +This function cannot know which name you will assign the generated function +so you must use \code{\link{Recall}} for recursive calls. } \examples{ linked_list := NIL | CONS(car, cdr : linked_list) lst <- CONS(1, CONS(2, CONS(3, NIL))) len <- case_trfunc(acc = 0, NIL -> acc, - CONS(car,cdr) -> len(cdr, acc + 1) + CONS(car,cdr) -> Recall(cdr, acc + 1) ) len(lst) list_sum <- case_trfunc(acc = 0, NIL -> acc, - CONS(car,cdr) -> list_sum(cdr, acc + car) + CONS(car,cdr) -> Recall(cdr, acc + car) ) list_sum(lst) diff --git a/vignettes/getting-started-with-pmatch-.Rmd b/vignettes/getting-started-with-pmatch-.Rmd index c643ae6..ddec29d 100644 --- a/vignettes/getting-started-with-pmatch-.Rmd +++ b/vignettes/getting-started-with-pmatch-.Rmd @@ -104,7 +104,7 @@ To define a linked list type we want to specify what the basic instances look li linked_list := NIL | CONS(car, cdr : linked_list) ``` -Here, I have used `car` for the head of a list and `cdr` for the tail. These are traditional names inherited from the [lisp programming language that in turn inherited them from IBM 704](https://en.wikipedia.org/wiki/CAR_and_CDR). I have chosen these names so we do not class with the R functions `head` and `tail`. This expression defines the type `linked_list`, specify that we can create objects of the type using one of the two constructores `NIL` or `CONS()`, where the former takes no arguments and the second two, of which the second argument must be another linked list. +Here, I have used `car` for the head of a list and `cdr` for the tail. These are traditional names inherited from the [lisp programming language that in turn inherited them from IBM 704](https://en.wikipedia.org/wiki/CAR_and_CDR). I have chosen these names so we do not class with the R functions `head` and `tail`. This expression defines the type `linked_list`, specify that we can create objects of the type using one of the two constructors `NIL` or `CONS()`, where the former takes no arguments and the second two, of which the second argument must be another linked list. We can create `a_list` using these constructors like this: @@ -124,7 +124,7 @@ list_length <- case_func( list_length(a_list) ``` -When we pattern-match like this, we also bind variables. In the `CONS(car, cdr)` pattern we didn't have to name the variables `car` and `cdr` just because we called them in the constructor. In the pattern matching they are just variables and they get set to the corresponding values in the structor of `the_list`. This is why we can use `cdr` in the expression we evaluate when we match the pattern—`cdr` will be bound to the tail of the list. +When we pattern-match like this, we also bind variables. In the `CONS(car, cdr)` pattern we didn't have to name the variables `car` and `cdr` just because we called them in the constructor. In the pattern matching they are just variables and they get set to the corresponding values in the structure of `the_list`. This is why we can use `cdr` in the expression we evaluate when we match the pattern—`cdr` will be bound to the tail of the list. We can also see this in another example where we sum all the elements in a list: