Re: [racket-users] Given any list, group n number of sublists into a single list

2017-05-19 Thread Matthew Butterick

> On May 19, 2017, at 7:52 AM, John Clements  wrote:
> 
> Sugar looks great; I just reimplemented your ‘filter-split’ for about the 
> seventeenth time yesterday while breaking a text file into paragraphs.


For that, I prescribe

`decode-paragraphs`

http://docs.racket-lang.org/pollen/Decode.html?q=decode-paragraphs#%28def._%28%28lib._pollen%2Fdecode..rkt%29._decode-paragraphs%29%29
 


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Given any list, group n number of sublists into a single list

2017-05-19 Thread 'John Clements' via users-redirect
Sugar looks great; I just reimplemented your ‘filter-split’ for about the 
seventeenth time yesterday while breaking a text file into paragraphs.

John



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Given any list, group n number of sublists into a single list

2017-05-17 Thread George Neuner


Doing people's homework are we?

On 5/17/2017 8:08 PM, Matthew Butterick wrote:

`slice-at`

http://docs.racket-lang.org/sugar/index.html?q=slice-at#%28def._%28%28lib._sugar%2Flist..rkt%29._slice-at%29%29 



On May 17, 2017, at 3:56 PM, Don Green > wrote:


Racket code that could perform this list manipulation?
(every-n-lists-into-list  '())
(every-n-lists-into-list 1 '((1) (2))) ;=> '(((1) (2)))
(every-n-lists-into-list 2 '((1) (2) (3) (4))) ;=> '(((1) (2)) ((3) (4)))
(every-n-lists-into-list 3 '((1) (2) (3) (4)) (5) (6))) ;=> '(((1) 
(2) (3)) ((4) (5) (6)))




Very nice!  Unfortunately, the existence of sugar was unknown to me 
until just now.   More evidence that one can spend a lifetime learning 
what batteries Racket already has included.



My 1st thought was to use split-at:

#lang racket
(define (group-items n items)

  ;; check # of items
  (unless (= 0 (modulo (length items) n))
(error "not enough items"))

  ;; split and reassemble
  (let loop [
 (items  items)
 (result '())
]
(if [null? items]
(reverse result)
(let-values [((head tail)(split-at items n))]
  (loop tail (cons head result)))
))
  )

George

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Given any list, group n number of sublists into a single list

2017-05-17 Thread Matthew Butterick
`slice-at`

http://docs.racket-lang.org/sugar/index.html?q=slice-at#%28def._%28%28lib._sugar%2Flist..rkt%29._slice-at%29%29
 



> On May 17, 2017, at 3:56 PM, Don Green  wrote:
> 
> Racket code that could perform this list manipulation?
> (every-n-lists-into-list  '())
> (every-n-lists-into-list 1 '((1) (2))) ;=> '(((1) (2)))
> (every-n-lists-into-list 2 '((1) (2) (3) (4))) ;=> '(((1) (2)) ((3) (4)))
> (every-n-lists-into-list 3 '((1) (2) (3) (4)) (5) (6))) ;=> '(((1) (2) (3)) 
> ((4) (5) (6)))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Given any list, group n number of sublists into a single list

2017-05-17 Thread Don Green
Racket code that could perform this list manipulation?
(every-n-lists-into-list  '())
(every-n-lists-into-list 1 '((1) (2))) ;=> '(((1) (2)))
(every-n-lists-into-list 2 '((1) (2) (3) (4))) ;=> '(((1) (2)) ((3) (4)))
(every-n-lists-into-list 3 '((1) (2) (3) (4)) (5) (6))) ;=> '(((1) (2) (3))
((4) (5) (6)))
Thanks
Don

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.