• Re: Listcomprehension-macro? Macros with args inside macro-name?

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Aug 13 12:26:08 2025
    From Newsgroup: comp.lang.lisp

    (loop for x in '(12 31 2 33)
    when (> x 20) collect (expt x 2))

    (filter-map~ x (and (> x 20) (* x x)) '(12 31 2 33))


    (961 1089)

    Given:

    (define-syntax filter-map~
    (syntax-rules ()
    [(_ (v0 v1 ...) expr seq0 seq1 ...)
    (filter-map (lambda(v0 v1 ...) expr) seq0 seq1 ...) ]
    [(_ v expr seq)
    (filter-map (lambda(v) expr) seq) ] ))
    --
    [T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
    --- Kenny Tilton
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Aug 13 12:56:59 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    (loop for x in '(12 31 2 33)
    when (> x 20) collect (expt x 2))

    (filter-map~ x (and (> x 20) (* x x)) '(12 31 2 33))


    (961 1089)

    Given:

    (define-syntax filter-map~
    (syntax-rules ()
    [(_ (v0 v1 ...) expr seq0 seq1 ...)
    (filter-map (lambda(v0 v1 ...) expr) seq0 seq1 ...) ]
    [(_ v expr seq)
    (filter-map (lambda(v) expr) seq) ] ))

    (keep x (> x 20) (* x x) '(12 31 2 33))

    Given:

    (define-syntax keep
    (syntax-rules ()
    [(_ v bool expr seq)
    (append-map (lambda(v) (if bool (list expr) '())) seq) ]
    [(_ v bool seq)
    (filter (lambda(v) bool) seq) ]
    [(_ pred seq) (filter pred seq) ]))
    --
    [T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
    --- Kenny Tilton
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2