On Tue, 9 Apr 2019 at 11:13, David Kastrup <[email protected]> wrote:

> Gianmaria Lari <[email protected]> writes:
>
> > On Tue, 9 Apr 2019 at 10:45, David Kastrup <[email protected]> wrote:
> >
> >> Gianmaria Lari <[email protected]> writes:
> >>
> >> > Suppose I write
> >> >
> >> >
> >> > #(define x '(1 2 3))
> >> >
> >> >
> >> > is there any way in scheme to print the memory address where x is
> >> pointing
> >> > to? (where is allocated the first element of the list)
> >>
> >> What do you need it for?  If it is for identification, (hashq x
> >> 1000000000) should usually do a reasonably good job.
> >>
> >
> > I tried, it looks working. (Yes, it's for identification)
> >
> > And is there any way to print the memory address of x? (If I remember
> > correctly was something like &x in c++).
>
> object-address maybe.  But it's not like you can use it for anything.



If I didn't make any mistakes, this code print the "address" of the first
element of the list x and the "address" of the first element pointed by the
parameter "lst" of the "foo" function.

\version "2.21.0"
#(define x '(1 2 3))
#(define (foo lst) (display (hashq lst 1000000000)))

#(display (hashq x 1000000000))#(newline)
#(foo x)


The two instructions


#(display (hashq x 1000000000))#(newline)
#(foo x)


print the same value because foo is called with x as argument and x and lst
refer to the same address.

I wanted to print the address of the variable x and then the address of the
parameter lst just to show that x and lst have different address (so  x is
passed by value. I could infer the same assigning to lst a new value and
see that at the exit of the function x didn't get update). I hope I didn't
say nothing wrong.

Best regards, g.
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to