Re: [racket-users] [racket users] list question

2021-02-25 Thread Kevin Forchione



> On Feb 25, 2021, at 10:12 AM, Norman Gray  wrote:
> 
> 
> I think this is called 'zip', or a convolution [1].  The variant you describe 
> is (effectively) with circular lists, but seems to be the same principle.
> 
> ...and I see that, with that name in hand, SRFI/1 does indeed have a zip 
> procedure, which works with circular lists.

Thanks, Norman! Looks like “zip” is the right name for the general process, and 
now that I can browse the docs for it there seems to be several flavors in 
various library modules, depending on creator intention.  I’ve generalized mine 
a bit to fit intention and some of theirs. 

(define/contract (zip #:length (len max) . lsts)
  (->* () (#:length (or/c procedure? natural?)) #:rest (listof list?) (listof 
list?))
  (define (loop cnt (acc empty))
(cond
  [(zero? cnt) acc]
  [else
   (define n (sub1 cnt))
   (loop n (cons (map (λ (lst) (list-ref lst (modulo n (length lst 
lsts) acc))]))
  (loop (cond
  [(procedure? len)
   (apply len (map length lsts))]
[else len])))

Kevin

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/650A2841-B8F8-4802-9116-7AB9876EA901%40gmail.com.


Re: [racket-users] [racket users] list question

2021-02-25 Thread Norman Gray



Kevin, hello.

On 25 Feb 2021, at 17:07, Kevin Forchione wrote:

As you can see each element of the sublist corresponds to the list-ref 
of the modulo n (length sublist) as n proceeds from 0 to  some maximum 
value. I’ve created a function that does exactly this, but … 
I’ve no idea what this process might be called. As they say, the 
naming of cats, and all that.Does this sort of mapping have a formal 
name?


I think this is called 'zip', or a convolution [1].  The variant you 
describe is (effectively) with circular lists, but seems to be the same 
principle.


...and I see that, with that name in hand, SRFI/1 does indeed have a zip 
procedure, which works with circular lists.


[1] https://en.wikipedia.org/wiki/Convolution_(computer_science)

Best wishes,

Norman


--
Norman Gray  :  https://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK

--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/7F1C9263-EA6A-4B5F-A0CF-15A5725E1EAE%40glasgow.ac.uk.