• Re: How do you insert declarations into loops?

    From B. Pym@21:1/5 to Thomas A. Russ on Tue Jul 2 10:24:36 2024
    Thomas A. Russ wrote:

    Example: This function loops over a list of associations
    collecting the cdrs.

    (defun list-cdrs (list)
    (loop for (unwanted-var . wanted-var) in list
    collect wanted-var))

    When I compile list-cdrs, I get an "unused lexical variable, UNWANTED-VAR" message (this is fine.). Normally, if I wanted to inhibit this
    warning I would stick a (declare (ignore unwanted-var)) in the
    beginning of the function body immediately following the declaration.
    It doesn't seem that you can do this using loop.

    The solution is not to introduce an ignore declartion, but instead to
    use a hack in the destructuring pattern matcher:

    (defun list-cdrs (list)
    (loop for (NIL . wanted-var) in list
    collect wanted-var))


    (map cdr '((a . 2) (b . 3)))

    (2 3)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to All on Mon Jun 23 01:52:32 2025
    How do you insert declarations into loops?

    Example: This function loops over a list of associations
    collecting the cdrs.

    (defun list-cdrs (list)
    (loop for (unwanted-var . wanted-var) in list
    collect wanted-var))

    When I compile list-cdrs, I get an "unused lexical variable, UNWANTED-VAR" message (this is fine.). Normally, if I wanted to inhibit this
    warning I would stick a (declare (ignore unwanted-var)) in the
    beginning of the function body immediately following the declaration.
    It doesn't seem that you can do this using loop.

    The solution is not to introduce an ignore declartion, but instead to
    use a hack in the destructuring pattern matcher:

    (defun list-cdrs (list)
    (loop for (NIL . wanted-var) in list
    collect wanted-var))

    Scheme

    (map cdr '((a . 2) (b . 3)))

    '(2 3)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Wed Jun 25 19:58:21 2025
    B. Pym wrote:

    How do you insert declarations into loops?

    Example: This function loops over a list of associations
    collecting the cdrs.

    (defun list-cdrs (list)
    (loop for (unwanted-var . wanted-var) in list
    collect wanted-var))

    When I compile list-cdrs, I get an "unused lexical variable, UNWANTED-VAR"
    message (this is fine.). Normally, if I wanted to inhibit this
    warning I would stick a (declare (ignore unwanted-var)) in the
    beginning of the function body immediately following the declaration.
    It doesn't seem that you can do this using loop.

    The solution is not to introduce an ignore declartion, but instead to
    use a hack in the destructuring pattern matcher:

    (defun list-cdrs (list)
    (loop for (NIL . wanted-var) in list
    collect wanted-var))

    Scheme

    (map cdr '((a . 2) (b . 3)))

    '(2 3)

    Is it true that users of CL inspired the movie "Idiocracy"?

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