• Re: [Newbie] passing keyword argument

    From B. Pym@21:1/5 to Carl Taylor on Thu Jul 18 07:39:18 2024
    Carl Taylor wrote:

    Here's a LOOP version of an index constructor.

    (defun make-index-list (obj seq &key (test #'eql))
    (loop for p = (position obj seq :test test :start (if p (1+ p) 0))
    while p
    collect p))

    (compile *)

    CL-USER 18 >
    (make-index-list
    '(0 1)
    '(a (6 2 z) (0 1) (1 2 3 4) (q w e r t y) (0 1) (foo) bar)
    :test #'equal)

    (2 5)

    Gauche Scheme

    (define (make-index-list obj seq :optional (test equal?))
    (filter-map
    (lambda(x i) (and (test obj x) i))
    seq
    (lrange 0)))

    (make-index-list
    '(0 1)
    '(a (6 2 z) (0 1) (1 2 3 4) (q w e r t y) (0 1) (foo) bar))

    ===>
    (2 5)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Fri Jul 19 17:25:45 2024
    On 2024-07-18, B. Pym <Nobody447095@here-nor-there.org> wrote:
    Carl Taylor wrote:

    Here's a LOOP version of an index constructor.

    (defun make-index-list (obj seq &key (test #'eql))
    (loop for p = (position obj seq :test test :start (if p (1+ p) 0))
    while p
    collect p))

    (compile *)

    CL-USER 18 >
    (make-index-list
    '(0 1)
    '(a (6 2 z) (0 1) (1 2 3 4) (q w e r t y) (0 1) (foo) bar)
    :test #'equal)

    (2 5)

    Gauche Scheme

    (define (make-index-list obj seq :optional (test equal?))
    (filter-map
    (lambda(x i) (and (test obj x) i))
    seq
    (lrange 0)))

    (make-index-list
    '(0 1)
    '(a (6 2 z) (0 1) (1 2 3 4) (q w e r t y) (0 1) (foo) bar))


    (2 5)

    This is the TXR Lisp interactive listener of TXR 295.
    Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
    TXR's no-spray organic production means every bug is carefully removed by hand.
    (where (op equal '(0 1)) '(a (6 2 z) (0 1) (1 2 3 4)
    (q w e r t y) (0 1) (foo) bar))
    (2 5)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

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