Commits

Pjotr Kourzanov committed 33cc1ea

switch to forall

Comments (0)

Files changed (1)

src/sequel/beseq.nw

 (gen-getter-num size)
 
 <<process>>=
-(define (for-all l p) (for-each p l))
 
 (define (gxf:activate n in)
-   (for-all ((sxpath "gxf/node[id=$n]/node") in
-		`([n . ,((sxpath "gxf/node[id=$n]/stereo-type/text()") in
-			`([n . ,(symbol->string n)]))]))
-	     (lambda (n)
-		(for-all ((sxpath "port") n)
-			  (lambda (p)
-			     (and (is-const p) (pp p))))
-		)
+   (forall [(n <- ((sxpath "gxf/node[id=$n]/node") in
+		     `([n . ,((sxpath "gxf/node[id=$n]/stereo-type/text()") in
+			`([n . ,(symbol->string n)]))])))]
+	   do (forall [(p <- ((sxpath "port") n))]
+		      do (and (is-const p) (pp p)))
 	     ))
 
 (define (gxf:collapse-code in)
 			      "]")
 			     ";")
 		        )) edges (array->list mb))
-	      (for-all cy (lambda (x)
-			   (labels ([find-activation (v a)
+	      (forall [(x <- cy)] 
+		      do (labels ([find-activation (v a)
 					(do [(i 0 (+ 1 i))]
 					    ((or (positive? (vector-ref v i))
 						 (>= i (vector-length v))) (list-ref a i)))
 				     [n (find-activation v actors)])
 				 ;(gxf:activate n in)
 				 (out (symbol->string n) "(" ");" )
-				 ))
-			   ))
+				 )))
 	      )))
 	 ))))
 
 						   (else def)))))
 
 
-@ A small printer.
-
-<<Miscellaneous>>=
-(define (out . x)
-   (let ([first #t])
-      (for-all x (lambda (x)
-	   (begin
-	      (or first (display " "))
-	      (set! first #f)
-	      (display x))
-	   )))
-      (newline))
-
 @ Check whether a certain property [[p]] holds for all elements of a vector.
   Since [[and]] is a special form, we define a funtional version, [[and-fun]] here in-place.
 
 			(else (apply and-fun (cdr x))))])     
       (apply and-fun (map p (vector->list v)))))
 
+@ Handy replacement macro for [[for-each]], [[filter]] and [[map]].
+
+<<Miscellaneous>>=
+(define (for-all l p) (for-each p l))
+
+(define-syntax forall
+   (syntax-rules (<- do where)
+      ([_ ((var <- l) ...) do a ...] (for-each (lambda (var ...) a ...) l ...))
+      ([_ ((var <- l) ...) where p ...] (filter (lambda (var ...) p ...) l ...))
+      ([_ ((var <- l) ...)] (map (lambda (var ...) (list var ...)) l ...))
+      ))
+
+@ A small printer.
+
+<<Miscellaneous>>=
+(define (out . l)
+   (let ([first #t])
+      (forall [(x <- l)] 
+	   do (begin
+	      (or first (display " "))
+	      (set! first #f)
+	      (display x))
+	   ))
+      (newline))
+
 @ \subsection{Trashbin}\label{ssec:trash}
 
 <<Trash>>=