Saturday 15 March 2014

Scheme zip function with possible uneven lists -


I know that before this question has been asked, and my solution is similar to the answers but I have a special Testing This problem, which will not work properly with the general solution of this problem.

Like many others, I have found a solution for the zip problem

  (define (zip L1 l2) (map list l1 l2))   

. Which is

  (zip '(ABC)' (1 2 3)) => Like works very well with given arguments.   

But I want to work with zip functions for those cases where my arguments do not match length like

  (Zip '(ABC) '(1)) =>   

I have not solved this problem and in fact it is not certain how to contact it where each list can be any length. First, a simple recurrence version that only works for 2 lists:

   

(ZIP '(ABC)' (1 2 3)) => '(A1) (B2) (C3)) (Zip (' ABC) '(1)) => '(A1) (B ()) (C ()))

This allows you to make N lists normal, but to avoid keyword parameters that you want to first placeholder parameters :

  (define (ZIP placeholder. LST) (define (my-car list) (if (empty? Listed) placeholder (car list)) (define (my-cdr) LST) (if (empty? LST) LST) (Loop (LSTS LSTS) (RSS) () (if (Endm (Empty) LSTS (Reverse Race) (Loop (Map my CDR LSTS)  
  (ZIP '()' (ABC) (Twenty (Apply to the map (my car LST)) ))))   

) '(1 2 3)) ==> (one1) (b2) (c3)) (zip' () '(a BC) '(1)) ==> '(A 1) (b ()) (c)) (zip' () '(abc)' (1) '(x y)) => I believe andmap is the only racket-specific function (a 1 x) (b () y) (c () ()))

Here, on the basis of your implementation there may be some scheme or SRFI equivalent.

Edit

Since the solution is based on making lists of the same length, instead to duplicate the zip algorithm, you can use the classic maplists Before placing content, first placeholder can be added to the list:

  (define (ZIP placeholder. LST) (* LAN (maximum length (LSTS length)); Longest Length of lists (equal length-lists; all Placeholders (map-placeholder (Lambda (LCT) list (- Max-Len (length lst)) placeholder))))))) (Apply map list on equal length-lists)) Adjusts the printers in the same length. ); Classic Zip    

No comments:

Post a Comment