Skip to content

Macros shouldn't be passed as arguments #4

@louiswins

Description

@louiswins

Expanding macros in-place can break lambdas at execution-time if the macro is passed as an argument:

(defun foldl (fn init lst) (if (null lst) init (foldl fn (fn init (car lst)) (cdr lst))))
(foldl + 0 (list 1 2 3)) ; => 6
(foldl or () (list () t)) ; => t
(foldl + 0 (list 1 2 3)) ; => 0

The second call to foldl actually expands the or inline into (fn init (car lst)) which breaks the third call (and all other subsequent ones). I found this bug in my own lisp implementation which has been heavily influenced by yours. I'm working on fixing it for myself but wanted to have a peek to see how you solved it - but you hadn't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions