• Re: Learning Lisp in Linux?

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Wed Aug 28 00:49:14 2024
    From Newsgroup: comp.lang.scheme

    Pascal Costanza wrote:

    I'm not advocating tail-recursion instead of specialized iteration mechanisms closer to the problem domain. I'm just saying tail-
    recursion code isn't anywhere as low-level as you're making it up to
    be.

    It actually is, and your posting below shows it very nicely.

    Here is a nice example using loop:

    (loop for (key value) on property-list by #'cddr
    unless (member key excluded-keys)
    append (list key value)) ; [1]

    As a function:

    (defun filter (excluded-keys property-list)
    (loop for (key value) on property-list by #'cddr
    unless (member key excluded-keys)
    nconc (list key value)))

    (filter '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    (A 1 B 2 B 3)

    The result is a correct property list

    Gauche Scheme

    (define (remove-props bad-keys prop-list)
    (concatenate
    (remove (^p (member (car p) bad-keys))
    (slices prop-list 2))))

    (remove-props '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    ===>
    (a 1 b 2 b 3)
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Wed Aug 28 01:38:46 2024
    From Newsgroup: comp.lang.scheme

    B. Pym wrote:

    Pascal Costanza wrote:

    I'm not advocating tail-recursion instead of specialized iteration mechanisms closer to the problem domain. I'm just saying tail-
    recursion code isn't anywhere as low-level as you're making it up to
    be.

    It actually is, and your posting below shows it very nicely.

    Here is a nice example using loop:

    (loop for (key value) on property-list by #'cddr
    unless (member key excluded-keys)
    append (list key value)) ; [1]

    As a function:

    (defun filter (excluded-keys property-list)
    (loop for (key value) on property-list by #'cddr
    unless (member key excluded-keys)
    nconc (list key value)))

    (filter '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    (A 1 B 2 B 3)

    The result is a correct property list

    Gauche Scheme

    (define (remove-props bad-keys prop-list)
    (concatenate
    (remove (^p (member (car p) bad-keys))
    (slices prop-list 2))))

    (remove-props '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    ===>
    (a 1 b 2 b 3)

    Nicolas Neuss wrote:

    does this look like assembly?

    (define (! n)
    (let loop ((x n) (r 1))
    (if (zero? x) r
    (loop (- x 1) (* x r)))))

    Yes, it does compared with

    (defun factorial (n)
    (loop for n from 1 upto n
    and f = 1 then (* f n)
    finally (return f)))

    It's shorter using "do".

    (define (fac n)
    (do ((i 1 (+ 1 i))
    (f 1 (* f i)))
    ((> i n) f)))

    (fac 5)
    ===>
    120

    Paul Graham:

    I consider Loop one of the worst flaws in CL, and an example
    to be borne in mind by both macro writers and language designers.

    Paul Graham, May 2001:

    A hacker's language is terse and hackable. Common Lisp is not.

    The good news is, it's not Lisp that sucks, but Common Lisp.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Sun Jun 22 20:44:57 2025
    From Newsgroup: comp.lang.scheme

    B. Pym wrote:

    Pascal Costanza wrote:

    I'm not advocating tail-recursion instead of specialized iteration mechanisms closer to the problem domain. I'm just saying tail-
    recursion code isn't anywhere as low-level as you're making it up to
    be.

    It actually is, and your posting below shows it very nicely.

    Here is a nice example using loop:

    (loop for (key value) on property-list by #'cddr
    unless (member key excluded-keys)
    append (list key value)) ; [1]

    As a function:

    (defun filter (excluded-keys property-list)
    (loop for (key value) on property-list by #'cddr
    unless (member key excluded-keys)
    nconc (list key value)))

    (filter '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    (A 1 B 2 B 3)

    The result is a correct property list

    Gauche Scheme

    (define (remove-props bad-keys prop-list)
    (concatenate
    (remove (^p (member (car p) bad-keys))
    (slices prop-list 2))))

    (remove-props '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    ===>
    (a 1 b 2 b 3)

    Using "is":

    (define (remove-props bad-keys prop-list)
    (concatenate
    (remove (is car member bad-keys)
    (slices prop-list 2))))


    Given:

    (define is
    (case-lambda
    [(x) (lambda(y) (equal? y x))]
    [(pred x) (lambda(y) (pred y x))]
    [(key pred x) (lambda(y) (pred (key y) x))]))
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Sun Jun 22 21:42:20 2025
    From Newsgroup: comp.lang.scheme

    B. Pym wrote:

    Pascal Costanza wrote:

    I'm not advocating tail-recursion instead of specialized iteration mechanisms closer to the problem domain. I'm just saying tail-
    recursion code isn't anywhere as low-level as you're making it up to
    be.

    It actually is, and your posting below shows it very nicely.

    Here is a nice example using loop:

    (loop for (key value) on property-list by #'cddr
    unless (member key excluded-keys)
    append (list key value)) ; [1]

    As a function:

    (defun filter (excluded-keys property-list)
    (loop for (key value) on property-list by #'cddr
    unless (member key excluded-keys)
    nconc (list key value)))

    (filter '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    (A 1 B 2 B 3)

    The result is a correct property list

    Gauche Scheme

    (define (remove-props bad-keys prop-list)
    (concatenate
    (remove (^p (member (car p) bad-keys))
    (slices prop-list 2))))

    (remove-props '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    ===>
    (a 1 b 2 b 3)


    Gauche Scheme

    (delete-keywords '(c d) '(a 1 b 2 b 3 c 4 d 5 c 6))
    ===>
    (a 1 b 2 b 3)
    --- Synchronet 3.22a-Linux NewsLink 1.2