• Re: How can "cons per call" be so different for these two

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Sat Sep 6 07:40:02 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    Well if you alway use these two functions together, it would be more >> efficient to generate both the results at once:
    ...
    The case could be made either way for this one, though, and certainly it would be better in terms of efficiency; thanks again for the suggestion.
    ...
    (defun split-on-corpus (atoms preprocessed-corpus)
    (loop :for atom :in atoms
    :if (gethash atom preprocessed-corpus)
    :collect atom :into present
    :else :collect atom :into absent
    :finally (return (list present absent))))

    Gauche Scheme

    (define table
    (alist->hash-table '((foo . 2)(bar . 4)(j . 5)(k . 3))))

    (define (split-on-corpus atoms corpus)
    ;; "!" is similar to "do".
    (! (atom :in atoms
    present cons atom
    absent cons atom
    :if-else (hash-table-exists? corpus atom))
    #f @@ (list present absent)))


    (split-on-corpus '(wow foo and bar or j is k) table)

    ===>
    ((foo bar j k) (wow and or is))
    --
    [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