Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in diamond wand equality #4

Closed
dtenny opened this issue Dec 30, 2022 · 2 comments
Closed

Bug in diamond wand equality #4

dtenny opened this issue Dec 30, 2022 · 2 comments

Comments

@dtenny
Copy link

dtenny commented Dec 30, 2022

Hi there. Just a note that there is a small problem if you want to diamond wand substitutions without :USE-ing the arrow-macros package. For example

(ql:quickload :arrow-macros)
(arrow-macros:-<>> 1 (print <>))

Yields

The variable <> is unbound.
   [Condition of type UNBOUND-VARIABLE]

This is because has-diamond (and similar checks) are using (eq exp '<>) which fails if the symbol was interned in a different package than the :arrow-macros package.

Instead you probably need a check like this:

(and (symbolp exp)
     (string= exp "<>"))
@dtenny
Copy link
Author

dtenny commented Dec 31, 2022

I suppose whether this is a bug is debatable, as I could package-qualify the <> symbol, e.g.
(arrow-macros:-<>> 3 (list arrow-macros:<> 1 2))

But that's kind of a drag in my book and it wasn't at all what I was expecting to to fix the unbound variable error problem.

@hipeta
Copy link
Owner

hipeta commented Jan 5, 2023

Thanks reporting.
I'm not native English speaker so some words or text may be wrong.

I suppose it's a specification issue.
If we use string= for checking <> symbol equality, it absorbs the package differences which the symbols belong to, but a:<> and b:<> are different things in common lisp.
It makes diamond-wands be "too strong" macro because it robs <> symbol semantics implicitly in all other packages.
I suppose it is unhealthy although <> symbol confliction rarely happens.

For example:

(ql:quickload :arrow-macros)

(defpackage a
  (:use :cl :arrow-macros)
  (:export :test))
(in-package :a)
(defmacro test (x)
  `(-<> 1 (+ 2 <>) (+ 3 <>) (+ ,x <>)))

(defpackage b
  (:use :cl :a))
(in-package :b)
(test (let ((<> 4)) <>))  

Using string= code, this causes an syntax error.
If package a and b are written by other persons, it will be bad behavior.
Therefore, I recommend using (import 'arrow-macros:<>), or including :use or :local-nicknames in your package definition.

@hipeta hipeta closed this as completed Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants