akashpal-21 / org-roam-utilities

Some utilities to use alongside org-roam
GNU General Public License v3.0
1 stars 1 forks source link

cl-loop vs mapcar #4

Closed dmgerman closed 2 months ago

dmgerman commented 2 months ago

cl-loop is a macro, and I suspect that it uses more memory than mapcar. See the following code:

#+begin_src emacs-lisp   :exports both
(cl-loop for row in (list (list 1 2) (list 2 3))
         collect (apply '+ row))
#+end_src

#+RESULTS:
| 3 | 5 |

#+begin_src emacs-lisp   :exports both
(mapcar (lambda (row)
          (apply '+ row)) (list (list 1 2) (list 2 3)))
#+end_src

#+RESULTS:
| 3 | 5 |

I would also avoid append when possible. mutation in general is bad :) and append (in theory) is less efficient than car.

akashpal-21 commented 2 months ago

When alias differentiation is true - the cl-loop append creates multiple nodes for the same ID one for each alias - I personally never want to use any cl-functions and wish to avoid it whenever possible - I do not vibe with Common Lisp --

But we have to create the same result - replacing the cl-loop collect would be trivial. But we should use the same logic for code readability alias differentiation is true or not.

If we can replace the cl-loop append easily we can then change cl-loop collect - but we should do this without increasing code complexity.