Here are a few examples of the practical use of LINQ in Scheme.  You may find more detailed information on some of these in our various Visual Scheme for ApplicationsTM Library documentation.



;; conformance to C# tests

;; simply permutations of the grammar and matched to the output 

;; of C#

(define (print-list lst)

  (foreach x in lst

    (printf "~a, " x))

  (printf "\n"))

 

(define selectdata  '(1 5 3 4 2))

(define groupdata   '(2 5 2 4 2))

(define nestdata    '((2 5)(2 4)(3 5)(3 1)(1 1)))

 

 

(define a ( from x in selectdata

            select x))

 

(print-list a)

 

(define a2 (from x in (from y in selectdata

                       select (+ y 1))

            select (- x 1)))

 

(print-list a2)

 

(define b ( from x in selectdata

            where (even? x)

            select x))

 

(print-list b)

 

(define c ( from x in selectdata

            orderby x

            select x))

 

(print-list c)

 

(define d ( from x in selectdata

            orderby x descending

            select x))

 

(print-list d)

 

(define e ( from x in selectdata

            where (odd? x)

            orderby x

            select x))

 

(print-list e)

 

(define f ( from x in selectdata

            let y = (* x x)

            select y))

 

(print-list f)

 

(define f2 (from x in selectdata

            let y = (* x x)

            where (odd? y)

            orderby y descending

            select y))

 

(print-list f2)

 

(define g ( from x in selectdata

            select x into z

            select z))

 

(print-list g)

 

(define h ( from x in nestdata

            from y in x

            select y))

 

(print-list h)

 

(define i ( from x in nestdata

            where (= (car x) 2)

            from y in x

            select y))

 

(print-list i)

 

(define j ( from x in nestdata

            orderby (car x)

            from y in x

            select y))

 

(print-list j)

 

(define k ( from x in nestdata

            from y in x

            orderby y

            select y))

 

(print-list k)

 

(define l ( from x in nestdata

            select x into y

            from z in y

            select z))

 

(print-list l)

 

(define m ( from x in nestdata

            group (car x) by (cadr x)))

 

(print-list m)

 

(define n ( from x in nestdata

            group (cadr x) by (car x)))

 

(print-list n)

 

(define o ( from x in nestdata

            group (cadr x) by (car x) into z

            select z))

 

(print-list o)

 

(define p ( from x in nestdata

            group (cadr x) by (car x) into z

            orderby (key z) descending

            select z))

 

(print-list p)

 

(define q ( from x in selectdata

            join y in groupdata on x equals y into z

            from w in z

            select w))

 

(print-list q)

 

(define r ( from x in selectdata

            join y in groupdata on x equals y

            select (cons x y)))

 

(print-list r)

 

(define s ( from x in selectdata

            from y in groupdata

            where (and (= x 4) (= y 2))

            select (cons x y)))

 

(print-list s)

 

(define t ( from x in selectdata

            join y in groupdata on x equals y into z

            orderby x

            select z))

 

(print-list t)

 

(define u ( from x in selectdata

            join y in groupdata on x equals y into z

            orderby x

            select (cons x z)))

 

(print-list u)

 

(define v ( from x in selectdata

            from y in groupdata 

            select y into z

            where (even? z)

            select z))

 

(print-list v)



 


The following terms are registered trademarks of the Microsoft group of companies and are used in accordance with Microsoft’s Trade and Brand Guidelines: Microsoft, Microsoft 365, Microsoft Office, Microsoft Excel, Microsoft Edge, Microsoft Edge WebView2, Microsoft Windows, Excel, Office 365


Copyright © 2022.  Apex Data Solutions, LLC. All Rights Reserved.