1

I am trying to initialize Magit Forge's forge-alist programatically. Therefore I put together my first couple of emacs-lisp code. It looks like the following:

(let ((gitlab-install (lambda (host) (list host (concat host "/api/v4") host forge-gitlab-repository))))
  (dolist (host '("gitlab.example.com" "gitlab.foobar.com"))
    (print host)
    (print (funcall gitlab-install host))
    (add-to-list 'forge-alist (funcall gitlab-install host))))

Unfortunately it seems that the final forge-alist has strange entries even though the (print) statement prints out the entries correctly.

((#1="gitlab.foobar.com" "gitlab.foobar.com/api/v4" #1# forge-gitlab-repository)
 (#2="gitlab.example.com" "gitlab.example.com/api/v4" #2# forge-gitlab-repository)
  ...)

What am I doing wrong?

3
1

You've created a list (using list) that shares structure. That's what that #1 syntax tells you.

(list host (concat host "/api/v4") host forge-gitlab-repository)

You pass, as the value of variable host, a string (e.g. "gitlab.example.com").

The anonymous function (lambda) then constructs a list whose first and third elements are each the value you pass it. That is, those elements are identical - the same string in this case. They're not copies (separate strings).

This tells you that:

(#1="gitlab.foobar.com" "gitlab.foobar.com/api/v4" #1# forge-gitlab-repository)

It shows a list whose first element is "gitlab.foobar.com", and which it identifies as the #1, and whose third element is shown as #1#, which refers to that same element - same string exactly.

If you don't want such shared structure then use copy-sequence to get separate strings with the same chars.

But maybe you do want to reuse exactly the same string. Only you can answer that (or perhaps someone acquainted with gitlab-install).

2
  • Thank you! The solution was as you recommended to create a copy of the string: (lambda (host) (list host (concat host "/api/v4") (copy-sequence host) forge-gitlab-repository)) – KARASZI István Nov 23 '20 at 16:42
  • The only question left behind in my head is why the originally created list wasn't working with forge. – KARASZI István Nov 23 '20 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.