Is there any way to get a variable address in Common Lisp?
Asked Answered
S

2

5

I'm trying to implement XOR-linked lists on Common Lisp, but i need to get an address of a variable to perform any bitwise operations on it. Is there any way to get memory address of a variable, similar to python's id() function?

Shavonneshaw answered 19/11, 2015 at 10:41 Comment(8)
If you need low-level things like addresses, Common Lisp is not the right tool; but it is a very good tool for high-level programming. Why do you need XOR-linked lists in Lisp?Aggappora
In Common Lisp addresses of variables make very little sense. Variables are often just pointers to objects.Demagogic
Garbage collection can move things around,and some entire can be copied whenever the implementation wants. So there's no reliable sense of address for what you're trying to do.Awad
You might find an unrolled linked list easier to implement in Common Lisp, with many of the same memory advantages.Awad
@BasileStarynkevitch actually, i was trying to do it just for the sake of doing it. I was interested if this can be implemented in lisp, and how hard it is to implement.Shavonneshaw
@RainerJoswig: I believe it is more appropriate to say that values are pointers to "objects" and variables contain such valuesAggappora
@JoshuaTaylor, I was trying to implement double-linked list, and as i saw it, xor-linked lists are a best way to implement using cons-cells. I guess i was wrongShavonneshaw
@BasileStarynkevitch: compare the definition of 'value' in Common Lisp: lispworks.com/documentation/HyperSpec/Body/26_glo_v.htm#value and also see variable under lispworks.com/documentation/HyperSpec/Body/…Demagogic
P
7

Usually, memory management in Common Lisp is performed by some kind of Garbage Collector. Many of these algorithms move the objects in memory during a collection cycle.

So the consequencies are that you cannot count on a fixed address for each object, and for this reason no operation in the standard is provided to get the address of a Common Lisp object.

Precipitancy answered 19/11, 2015 at 11:14 Comment(0)
G
0

If you're using Allegro Common Lisp, maybe this is what you're looking for: Escape from the Heap: Low-Level Programming in Common Lisp

Goring answered 24/11, 2015 at 1:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.