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

copy-tree does not copy float-vector #475

Open
knorth55 opened this issue Dec 14, 2021 · 4 comments
Open

copy-tree does not copy float-vector #475

knorth55 opened this issue Dec 14, 2021 · 4 comments

Comments

@knorth55
Copy link
Contributor

knorth55 commented Dec 14, 2021

I know copy-tree is for list, but copy-tree returns no error with float-vector and does not copy the vector.
It is better to warn copy-tree with float-vector.

1.irteusgl$ (setq a  (float-vector 1 2 3))
#f(1.0 2.0 3.0)
2.irteusgl$ (setq b (copy-tree a))
#f(1.0 2.0 3.0)
3.irteusgl$ (setf (elt b 0) 5)
5
4.irteusgl$ a
#f(5.0 2.0 3.0)
5.irteusgl$ b
#f(5.0 2.0 3.0)
@Affonso-Gui
Copy link
Member

The implementation explicitly returns the non-cloned value when the argument is not a list, so this doesn't seem like some sort of upredicted side effect (i.e. designed for lists but that "accidentally" could handle other sequence types).
https://github.com/euslisp/EusLisp/blob/master/lisp/c/lists.c#L236

I am not sure if we should solve this by changing the implementation to also copy non-lists; add a warning; or just add more specific jmanual documentation. However, this is very similar to #361 , which promises destructive results but only delivers that on some cases.

@knorth55
Copy link
Contributor Author

I think it is better to keep old behavior for keep backward compatibility, but we can warn the misusage or non-copied behavior.
so I open a PR #476

@Affonso-Gui
Copy link
Member

Affonso-Gui commented Dec 15, 2021

(just for future reference I would like to add that in this case copy-seq does what you want)

irteusgl> (setq a (float-vector 1 2 3))
#f(1.0 2.0 3.0)
irteusgl> (setq b (copy-seq a))
#f(1.0 2.0 3.0)
irteusgl> (setf (elt b 0) 5)
5
irteusgl> a
#f(1.0 2.0 3.0)
irteusgl> b
#f(5.0 2.0 3.0)

irteusgl> (sys:address a)
94797007551080
irteusgl> (sys:address b)
94797007912976

EDIT: or copy-object if you need a deep copy

@knorth55
Copy link
Contributor Author

knorth55 commented Dec 15, 2021

copy-seq, which I use it for float-vector normally.
I misused copy-tree for float-vector, which returns non-cloned float-vector, and I spent several hours for debugging it.

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