• Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?

    From B. Pym@21:1/5 to Wade Humeniuk on Fri Jul 5 22:36:05 2024
    Wade Humeniuk wrote:

    John Connors wrote:

    Yet Another Noob Question.

    What are the characteristics of each implementation?

    How can I tell which I should be writing in what context...

    (defun find-indicies (lst tst)
    (let ((li 0))
    (labels ((qpred (a)
    (incf li)
    (if (funcall tst a)
    (1- li)
    nil)))
    (remove nil (mapcar #'qpred lst)))))

    (defun find-indices (lst tst)
    (loop
    for el in lst
    counting t into index
    if (funcall tst el)
    collect index))

    You are allergic to loop

    (defun find-indices (list test)
    (loop for element in list
    for index from 1
    when (funcall test element) collect index))

    Gauche Scheme

    (define (find-indices lst test)
    (filter-map
    (lambda (e i) (and (test e) i))
    lst
    (lrange 1)))

    (find-indices '(0 88 409 66 77) odd?)
    ===>
    (3 5)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to Wade Humeniuk on Mon Aug 19 07:20:00 2024
    Wade Humeniuk wrote:

    John Connors wrote:

    Yet Another Noob Question.

    What are the characteristics of each implementation?

    How can I tell which I should be writing in what context...

    (defun find-indicies (lst tst)
    (let ((li 0))
    (labels ((qpred (a)
    (incf li)
    (if (funcall tst a)
    (1- li)
    nil)))
    (remove nil (mapcar #'qpred lst)))))

    (defun find-indices (lst tst)
    (loop
    for el in lst
    counting t into index
    if (funcall tst el)
    collect index))

    You are allergic to loop

    (defun find-indices (list test)
    (loop for element in list
    for index from 1
    when (funcall test element) collect index))

    newLISP

    (define (find-indices lst test)
    (index test lst))

    (find-indices '(200 209 250 257 260 263) odd?)
    ===>
    (1 3 5)

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