Reimplement and document ldict-filter.
This commit is contained in:
		
							parent
							
								
									bd7421b626
								
							
						
					
					
						commit
						90fa195dc5
					
				
					 2 changed files with 20 additions and 9 deletions
				
			
		|  | @ -179,15 +179,17 @@ | |||
|  ;; Returns a dictionary containing only kv pairs matching the | ||||
|  ;; predicate which must accept two arguments. Unlike list filter, | ||||
|  ;; does not perform final reverse on the result. | ||||
|  (define (dict-filter pred? d) | ||||
|    (let loop ((d d) | ||||
| 	      (r '())) | ||||
|      (if (null? d) | ||||
| 	 r | ||||
| 	 (loop (cdr d) | ||||
| 	       (if (pred? (caar d) (cdar d)) | ||||
| 		   (cons (car d) r) | ||||
| 		   r))))) | ||||
|  (define (ldict-filter pred? ld) | ||||
|    (let loop ((pairs (ldict-pairs ld)) | ||||
| 	      (res '())) | ||||
|      (if (null? pairs) | ||||
| 	 (cons TAG-LDICT | ||||
| 	       (cons (ldict-meta ld) | ||||
| 		     res)) | ||||
| 	 (loop (cdr pairs) | ||||
| 	       (if (pred? (caar pairs) (cdar pairs)) | ||||
| 		   (cons (car pairs) res) | ||||
| 		   res))))) | ||||
| 
 | ||||
|  ;; Reduce over dictinary, the reducing procedure gets accumulator, | ||||
|  ;; key and value as its three arguments. | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue