On Friday, February 12, 2016 at 1:26:05 AM UTC, Matthew Butterick wrote:
> Of course, you can also use the `at-exp` metalanguage from Scribble to 
> simplify text-heavy constructions like these, with variables interpolated 
> into strings:

> #lang at-exp racket
> 
> (define (query condA condB (limit #f) (offset #f))
>   @~a{SELECT something FROM table WHERE @condA AND @condB @(if limit
>                                                                @~a{LIMIT 
> @limit @(if offset
>                                                                               
>        @~a{OFFSET @offset}
>                                                                               
>        "")}
>                                                                "")})

I could also do this:

(define (query condA condB (limit #f) (offset #f))
  (flatten
    (list "SELECT something FROM table WHERE "
                condA
                " AND "
                condB
                (if limit
                        (list "LIMIT " limit
                                  (if offset
                                          (list "OFFSET " offset)
                                          '()))
                        '())))

at-exp really is a fascinating language, but if a (flatten) isn't any more 
computationally expensive, you can just splice all the lists at the end and use 
the regular racket language. Either way would work fine, I suspect.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to