• Re: help me with this function

    From B. Pym@21:1/5 to Kenny Tilton on Tue Jul 2 09:44:11 2024
    i'm trying to write a function that takes two arguments - one is
    an ato the other is a list of lists - for each list within the
    list, if the atom matches its first memeber, i want it's second
    member to be added to a master list and finally returned- for
    example:

    (setq mylist '((a b)(a c)(a d)))
    (myfunc 'a lst)

    and myfunc would return

    (b c d)

    Kenny Tilton wrote:

    I do not know of a one-step solution, but you could try:

    (defun cullCar (match lists)
    (delete-if #'null (mapcar #'(lambda (list)
    (when (eql match (car list))
    (cadr list)))
    lists)))

    This would be inefficent where many non-matches occur. Doesn't
    the loop macro have some neat features for this? (Don't use it
    myself.)

    Scheme

    (define (myfunc x lst)
    (filter-map
    (lambda(xs) (and (equal? x (car xs)) (cadr xs)))
    lst))

    (myfunc 'b '((b 2) (c 3) (b 4) (d 5) (b 6)))

    ===>
    (2 4 6)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Tue Jul 2 10:24:46 2024
    On 2024-07-02, B. Pym <No_spamming@noWhere_7073.org> wrote:
    i'm trying to write a function that takes two arguments - one is
    an ato the other is a list of lists - for each list within the
    list, if the atom matches its first memeber, i want it's second
    member to be added to a master list and finally returned- for
    example:

    (setq mylist '((a b)(a c)(a d)))
    (myfunc 'a lst)

    and myfunc would return

    (b c d)

    (match @(coll (a @x)) '((a b) (a c) (a d) (x 0) (a e)) x)
    (b c d e)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to B. Pym on Tue Jul 2 17:03:12 2024
    "B. Pym" <No_spamming@noWhere_7073.org> writes:
    (myfunc 'b '((b 2) (c 3) (b 4) (d 5) (b 6)))
    ===>
    (2 4 6)

    (myfunc 'b '((b 2) (c 3) (b #f) (d 5) (b 6)))
    ===>
    (2 6)

    Should be (2 #f 6).

    This works:

    (define (m2 x lst)
    (map cadr (filter (lambda (ys) (equal? (car ys) x)) lst)))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)