Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-19 Thread Michael Tiedtke

Il giorno 18/mag/2015, alle ore 21.34, Jens Axel Søgaard ha scritto:

 
 
 2015-05-18 21:25 GMT+02:00 Michael Tiedtke michael.tied...@o2online.de:
 Il giorno 18/mag/2015, alle ore 20.50, Jos Koot ha scritto:
 
  I think Rackets's reference and guide are *very clear* about eq?, eqv? and
  equal?.
 
 Yes, right. It was the Racket Reference to tell me exactly that eqv? is an 
 eq? that
 works for numbers and characters, too. I really had to look this up and found 
 an
 simple and concise description.
 
 But the entries for for-each and map do not state anything about the 
 execution order
 of the list processing.
 
 Here is what the documentation say:
 
   Racket docs: Applies proc to the elements of the lsts from the first 
 elements to the last. 
   R5RS: The dynamic order in which proc is applied to the elements of the 
 lists is unspecified.
 
 I interpret the Racket docs to mean that the procedure are applied to the 
 elements in the list in the order they appear in the list.
 
 In contrast R5RS (on purpose) state that the order is unspecified, which 
 means that an implementor of R5RS Scheme is free to choose the order which 
 fits his system best. Potentially the freedom to choose the order could 
 enable some optimizations.

the order for map is unspecified so that it can be optimized.
for-each guarantees to call proc in  order from list head to list tail.

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Michael Tiedtke
Structure and Interpretation of Computer Programs (sicp2) about sameness:

https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html#footnote_Temp_230
 We can consider two symbols to be ``the same'' if they consist of the same 
 characters in the same order. Such a definition skirts a deep issue that we 
 are not yet ready to address: the meaning of ``sameness'' in a programming 
 language. We will return to this in chapter 3 (section 3.1.3).

https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-20.html#%25_idx_2994
 A language that supports the concept that ``equals can be substituted for 
 equals'' in an expresssion without changing the value of the expression is 
 said to be referentially transparent. Referential transparency is violated 
 when we include set! in our computer language. This makes it tricky to 
 determine when we can simplify expressions by substituting equivalent 
 expressions. Consequently, reasoning about programs that use assignment 
 becomes drastically more difficult.
 
 Once we forgo referential transparency, the notion of what it means for 
 computational objects to be ``the same'' becomes difficult to capture in a 
 formal way. Indeed, the meaning of ``same'' in the real world that our 
 programs model is hardly clear in itself. In general, we can determine that 
 two apparently identical objects are indeed ``the same one'' only by 
 modifying one object and then observing whether the other object has changed 
 in the same way. But how can we tell if an object has ``changed'' other than 
 by observing the ``same'' object twice and seeing whether some property of 
 the object differs from one observation to the next? Thus, we cannot 
 determine ``change'' without some a priori notion of ``sameness,'' and we 
 cannot determine sameness without observing the effects of change.

Maybe the uncertainities of wether to use eq?, eqv? or equal? have their roots 
in the general concept of sameness and the needs of different implementations. 
Two symbols with the same sequence of characters should be eq? and eqv?.

But eq? is not well defined for numbers: (eq? 2 2) is unspecified but what 
about (eq? '2 '2)?
(+ '1 '2) = 3 because the reader treats numerical symbols in another way.

Anyway (eq? 'l 'l) should always be true even though this morning I read it as 
(eq? 1 1) which looks almost the same.


Il giorno 18/mag/2015, alle ore 07.28, Alexis King ha scritto:

 Yes, Scheme (and therefore Racket) has eq?, eqv?, and equal?. I understand 
 the desire for eq? and equal?, but I’ve always been skeptical of the 
 necessity of eqv?. Either way, Scheme left this behavior unspecified, but I 
 believe Racket specifies it (though I could be wrong).
 
 Racket has two kinds of symbols, interned and uninterned. Symbols produced by 
 the reader, whether via read or read-syntax, are interned. Additionally, 
 string-symbol produces interned symbols. Certain functions such as gensym 
 and string-uninterned-symbol produce uninterned symbols, but these are not 
 commonly encountered, anyway.
 
 Interned symbols, I believe, are guaranteed to be eq? since they’re, well, 
 interned. There is a pool of interned symbols such that all symbols made up 
 of the same string are all the same object, so they’re all eq?.
 
 I can’t reproduce the behavior in the original message, and I don’t think it 
 should be possible.
 
 On May 17, 2015, at 22:19, Michael Tiedtke michael.tied...@o2online.de 
 wrote:
 
 I'm new to Racket but even R5RS is rather clear about this issue:
 
 (citation from doc/r5rs/r5rs-std/r5rs-Z-H-9.html)
 (eq? 2 2)   ===  unspecified
 
 Rationale:   It will usually be possible to implement eq? much more 
 efficiently than eqv?, for example, as a simple pointer comparison instead 
 of as some more complicated operation. One reason is that it may not be 
 possible to compute eqv? of two numbers in constant time, whereas eq? 
 implemented as pointer comparison will always finish in constant time. Eq? 
 may be used like eqv? in applications using procedures to implement objects 
 with state since it obeys the same constraints as eqv?.
 
 
 You should use = with numbers as far as I remember.
 
 
 Il giorno 18/mag/2015, alle ore 02.41, George Neuner ha scritto:
 
 Hi,
 
 On 5/17/2015 5:32 PM, Atticus wrote:
 ---
 $ racket
 Welcome to Racket v6.1.1.
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 
 
 $ racket --no-jit
 Welcome to Racket v6.1.1.
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #f
 
 
 ---
 
 How to reproduce this behaviour? Just start racket from the command line
 and type '(eq? 'l 'l), this should return #f (or sometimes #t). The next
 time the same expression returns #t. Whats also interesting is that with
 the command line option --no-jit the return value seems to randomly
 change between #t and #f.   ...
 
 I can't reproduce this.  Might there have been some control 

Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Matthias Felleisen

SICP isn' the bible, especially not on programming language knowledge. I'd 
recommend checking out relevant literature instead. 








On May 18, 2015, at 8:24 AM, Michael Tiedtke michael.tied...@o2online.de 
wrote:

 Structure and Interpretation of Computer Programs (sicp2) about sameness:
 
 https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html#footnote_Temp_230
 We can consider two symbols to be ``the same'' if they consist of the same 
 characters in the same order. Such a definition skirts a deep issue that we 
 are not yet ready to address: the meaning of ``sameness'' in a programming 
 language. We will return to this in chapter 3 (section 3.1.3).
 
 https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-20.html#%25_idx_2994
 A language that supports the concept that ``equals can be substituted for 
 equals'' in an expresssion without changing the value of the expression is 
 said to be referentially transparent. Referential transparency is violated 
 when we include set! in our computer language. This makes it tricky to 
 determine when we can simplify expressions by substituting equivalent 
 expressions. Consequently, reasoning about programs that use assignment 
 becomes drastically more difficult.
 
 Once we forgo referential transparency, the notion of what it means for 
 computational objects to be ``the same'' becomes difficult to capture in a 
 formal way. Indeed, the meaning of ``same'' in the real world that our 
 programs model is hardly clear in itself. In general, we can determine that 
 two apparently identical objects are indeed ``the same one'' only by 
 modifying one object and then observing whether the other object has changed 
 in the same way. But how can we tell if an object has ``changed'' other than 
 by observing the ``same'' object twice and seeing whether some property of 
 the object differs from one observation to the next? Thus, we cannot 
 determine ``change'' without some a priori notion of ``sameness,'' and we 
 cannot determine sameness without observing the effects of change.
 
 Maybe the uncertainities of wether to use eq?, eqv? or equal? have their 
 roots in the general concept of sameness and the needs of different 
 implementations. Two symbols with the same sequence of characters should be 
 eq? and eqv?.
 
 But eq? is not well defined for numbers: (eq? 2 2) is unspecified but what 
 about (eq? '2 '2)?
 (+ '1 '2) = 3 because the reader treats numerical symbols in another way.
 
 Anyway (eq? 'l 'l) should always be true even though this morning I read it 
 as (eq? 1 1) which looks almost the same.
 
 
 Il giorno 18/mag/2015, alle ore 07.28, Alexis King ha scritto:
 
 Yes, Scheme (and therefore Racket) has eq?, eqv?, and equal?. I understand 
 the desire for eq? and equal?, but I’ve always been skeptical of the 
 necessity of eqv?. Either way, Scheme left this behavior unspecified, but I 
 believe Racket specifies it (though I could be wrong).
 
 Racket has two kinds of symbols, interned and uninterned. Symbols produced 
 by the reader, whether via read or read-syntax, are interned. Additionally, 
 string-symbol produces interned symbols. Certain functions such as gensym 
 and string-uninterned-symbol produce uninterned symbols, but these are not 
 commonly encountered, anyway.
 
 Interned symbols, I believe, are guaranteed to be eq? since they’re, well, 
 interned. There is a pool of interned symbols such that all symbols made up 
 of the same string are all the same object, so they’re all eq?.
 
 I can’t reproduce the behavior in the original message, and I don’t think it 
 should be possible.
 
 On May 17, 2015, at 22:19, Michael Tiedtke michael.tied...@o2online.de 
 wrote:
 
 I'm new to Racket but even R5RS is rather clear about this issue:
 
 (citation from doc/r5rs/r5rs-std/r5rs-Z-H-9.html)
 (eq? 2 2)   ===  unspecified
 
 Rationale:   It will usually be possible to implement eq? much more 
 efficiently than eqv?, for example, as a simple pointer comparison instead 
 of as some more complicated operation. One reason is that it may not be 
 possible to compute eqv? of two numbers in constant time, whereas eq? 
 implemented as pointer comparison will always finish in constant time. Eq? 
 may be used like eqv? in applications using procedures to implement 
 objects with state since it obeys the same constraints as eqv?.
 
 
 You should use = with numbers as far as I remember.
 
 
 Il giorno 18/mag/2015, alle ore 02.41, George Neuner ha scritto:
 
 Hi,
 
 On 5/17/2015 5:32 PM, Atticus wrote:
 ---
 $ racket
 Welcome to Racket v6.1.1.
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 
 
 $ racket --no-jit
 Welcome to Racket v6.1.1.
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #f
 
 
 ---
 
 How to reproduce this behaviour? Just start racket from the command line
 and type '(eq? 'l 'l), this should return #f (or sometimes #t). The 

Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Atticus
George Neuner gneun...@comcast.net writes:

 Hi,

 On 5/17/2015 5:32 PM, Atticus wrote:
 ---
 $ racket
 Welcome to Racket v6.1.1.
  (eq? 'l 'l)
 #f
  (eq? 'l 'l)
 #t
 

 $ racket --no-jit
 Welcome to Racket v6.1.1.
  (eq? 'l 'l)
 #f
  (eq? 'l 'l)
 #t
  (eq? 'l 'l)
 #f
  (eq? 'l 'l)
 #t
  (eq? 'l 'l)
 #t
  (eq? 'l 'l)
 #t
  (eq? 'l 'l)
 #f
  (eq? 'l 'l)
 #f
 

 ---

 How to reproduce this behaviour? Just start racket from the command line
 and type '(eq? 'l 'l), this should return #f (or sometimes #t). The next
 time the same expression returns #t. Whats also interesting is that with
 the command line option --no-jit the return value seems to randomly
 change between #t and #f.   ...

 I can't reproduce this.  Might there have been some control characters 
 accidentally in your input?


Since i can not reproduce this behavior reliably anymore and because
this happend only while typing the expression by hand that should be the
most plausible explanation.

Thanks to everyone for your help

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Michael Tiedtke
Il giorno 18/mag/2015, alle ore 18.06, Atticus ha scritto:

 I guess it's a matter of definition. I must admit that i didn't reflect
 on equality that much.
 
 My (very limited) knowledge about that stuff comes mostly from the The
 Little Schemer which imho explains it really well with the 'eqan?' and
 'eqlist?' procedure.
 
 The reason why i checked (eq? 'symbol1 'symbol2) in the first place in
 racket was because in gambit scheme (eq? string string) returned #f
 and in racket returns #t. I just wanted to check the differences between
 racket and gambit and was really surprised as (eq? 'symbol1 'symbol2)
 returned #f in the racket repl (which was likely because of escape
 characters)

It's great to see someone do these checks. I guess it's important to realize
that (eq? 'symbol 'symbol) should always return true because of its definition.
If it does not return true than that would be a real error and as symbols are
usually used all over the place to denote unimplemented concepts the system
would break early on. I was not able reproduce the described behavior but
one never knows ...

Comparing  two strings on the other hand is not defined for eq? or let's say 
it's
defined as unspecified. That's because some implementations might create a
new data object for each string and return #f for (eq? string string). Other
implementations try to save memory and realize that string and string have
the same content so they can be substituted by a pointer to one data structure
containing string. But I cannot rely on that behavior because in other 
situations
the same string might be represented by another pointer to a different data
structure. So eq? only checks for equality of pointers to data structures. Two
different lists with the same content are not equal because list creates a new
data object each time it's called: (eq? (list 'a) (list 'a)) = #f
The only exception to that definition is the empty list '() (or null):
(eq? '() '()) returns true by definition.
Comparing two empty strings with (eq?  ) does not make sense on the other
hand because the return value of eq? is unspecified when comparing strings.
Unspecified means it might be true, it might be false but I cannot count on it.

To check for the equality of strings one needs to use equal? which is defined to
analyze the contents of the data structures and not the pointers. Same for lists
(equal? (list 'a) (list 'a)) = true
(equal? string string) = true

Rackets 's reference and guide sometimes are a bit vague about these things.
So it's better to check their current standard R6RS. When you open the
documentation and search for eq? you should see several results:
rnrs/base-6 is the one you want to have a look at. But as far as I could see 
Gambit
does not support R6RS so you might want to check r5rs, too.

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Atticus
I guess it's a matter of definition. I must admit that i didn't reflect
on equality that much.

My (very limited) knowledge about that stuff comes mostly from the The
Little Schemer which imho explains it really well with the 'eqan?' and
'eqlist?' procedure.

The reason why i checked (eq? 'symbol1 'symbol2) in the first place in
racket was because in gambit scheme (eq? string string) returned #f
and in racket returns #t. I just wanted to check the differences between
racket and gambit and was really surprised as (eq? 'symbol1 'symbol2)
returned #f in the racket repl (which was likely because of escape
characters)

Michael Tiedtke michael.tied...@o2online.de writes:

 Structure and Interpretation of Computer Programs (sicp2) about sameness:

 https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html#footnote_Temp_230
 We can consider two symbols to be ``the same'' if they consist of the same 
 characters in the same order. Such a definition skirts a deep issue that we 
 are not yet ready to address: the meaning of ``sameness'' in a programming 
 language. We will return to this in chapter 3 (section 3.1.3).

 https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-20.html#%25_idx_2994
 A language that supports the concept that ``equals can be substituted for 
 equals'' in an expresssion without changing the value of the expression is 
 said to be referentially transparent. Referential transparency is violated 
 when we include set! in our computer language. This makes it tricky to 
 determine when we can simplify expressions by substituting equivalent 
 expressions. Consequently, reasoning about programs that use assignment 
 becomes drastically more difficult.
 
 Once we forgo referential transparency, the notion of what it means for 
 computational objects to be ``the same'' becomes difficult to capture in a 
 formal way. Indeed, the meaning of ``same'' in the real world that our 
 programs model is hardly clear in itself. In general, we can determine that 
 two apparently identical objects are indeed ``the same one'' only by 
 modifying one object and then observing whether the other object has changed 
 in the same way. But how can we tell if an object has ``changed'' other than 
 by observing the ``same'' object twice and seeing whether some property of 
 the object differs from one observation to the next? Thus, we cannot 
 determine ``change'' without some a priori notion of ``sameness,'' and we 
 cannot determine sameness without observing the effects of change.

 Maybe the uncertainities of wether to use eq?, eqv? or equal? have their 
 roots in the general concept of sameness and the needs of different 
 implementations. Two symbols with the same sequence of characters should be 
 eq? and eqv?.

 But eq? is not well defined for numbers: (eq? 2 2) is unspecified but what 
 about (eq? '2 '2)?
 (+ '1 '2) = 3 because the reader treats numerical symbols in another way.

 Anyway (eq? 'l 'l) should always be true even though this morning I read it 
 as (eq? 1 1) which looks almost the same.


 Il giorno 18/mag/2015, alle ore 07.28, Alexis King ha scritto:

 Yes, Scheme (and therefore Racket) has eq?, eqv?, and equal?. I understand 
 the desire for eq? and equal?, but I’ve always been skeptical of the 
 necessity of eqv?. Either way, Scheme left this behavior unspecified, but I 
 believe Racket specifies it (though I could be wrong).
 
 Racket has two kinds of symbols, interned and uninterned. Symbols produced 
 by the reader, whether via read or read-syntax, are interned. Additionally, 
 string-symbol produces interned symbols. Certain functions such as gensym 
 and string-uninterned-symbol produce uninterned symbols, but these are not 
 commonly encountered, anyway.
 
 Interned symbols, I believe, are guaranteed to be eq? since they’re, well, 
 interned. There is a pool of interned symbols such that all symbols made up 
 of the same string are all the same object, so they’re all eq?.
 
 I can’t reproduce the behavior in the original message, and I don’t think it 
 should be possible.
 
 On May 17, 2015, at 22:19, Michael Tiedtke michael.tied...@o2online.de 
 wrote:
 
 I'm new to Racket but even R5RS is rather clear about this issue:
 
 (citation from doc/r5rs/r5rs-std/r5rs-Z-H-9.html)
 (eq? 2 2)   ===  unspecified
 
 Rationale:   It will usually be possible to implement eq? much more 
 efficiently than eqv?, for example, as a simple pointer comparison instead 
 of as some more complicated operation. One reason is that it may not be 
 possible to compute eqv? of two numbers in constant time, whereas eq? 
 implemented as pointer comparison will always finish in constant time. Eq? 
 may be used like eqv? in applications using procedures to implement 
 objects with state since it obeys the same constraints as eqv?.
 
 
 You should use = with numbers as far as I remember.
 
 
 Il giorno 18/mag/2015, alle ore 02.41, George Neuner ha scritto:
 
 Hi,
 
 On 5/17/2015 5:32 PM, Atticus wrote:
 

RE: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Jos Koot
I think Rackets's reference and guide are *very clear* about eq?, eqv? and
equal?.
They are even described well for structures and hashes and much more.
Be aware, though, that in general equality can be interpreted in many ways.
At the mathematical level equality is a difficult and in many cases even an
unsolvable thing.

Jos




-Original Message-
From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com]
On Behalf Of Michael Tiedtke
Sent: lunes, 18 de mayo de 2015 19:00
To: racket-users@googlegroups.com
Subject: Re: [racket-users] Strange behaviour of the eq? operator in racket
repl

SNIP

Rackets 's reference and guide sometimes are a bit vague about these things.
So it's better to check their current standard R6RS. When you open the
documentation and search for eq? you should see several results:
rnrs/base-6 is the one you want to have a look at. But as far as I could see
Gambit
does not support R6RS so you might want to check r5rs, too.

SNIP

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Greg Hendershott
In my early time learning Racket, I wish someone had given me the
following advice:


For now? Just use `equal?`.

`equal?` will usually do the right thing, including for numbers,
strings, symbols, immutable lists, and so on. A type-specific function
like `=` or `string-=?` might be a bit faster. `eq?` might be a lot
faster. But `equal?` will still be correct.

`eq?` or `eqv?` might matter semantically if you're doing certain
things -- but you're not likely to be doing them in your early days
with Racket. So if you're getting side-tracked and confused, you can
probably set it aside for now, and just use `equal?`


That advice might make some of you cringe as simplistic, but it would
have been a helpful simplification for me. And I'm talking about
modern Racket, not Schemes generally.

Of course there are also things like `egal?` that are fun to learn
about, eventually.

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Michael Tiedtke
Il giorno 18/mag/2015, alle ore 20.50, Jos Koot ha scritto:

 I think Rackets's reference and guide are *very clear* about eq?, eqv? and
 equal?.

Yes, right. It was the Racket Reference to tell me exactly that eqv? is an eq? 
that
works for numbers and characters, too. I really had to look this up and found an
simple and concise description.

But the entries for for-each and map do not state anything about the execution 
order
of the list processing. The other entry whose description I found a bit 
confusing was
cond - I always need to look that up no matter which Scheme I'm on because I
always (want to) forget that it takes only the first branch whose condition is 
true and
ignores the rest. Perhaps someday they will change this but R5RS states that 
behavior
clearly enough. That's what I meant when I wrote the guide and the reference
are sometimes a bit vague about these things and I'm sorry about being too 
vague
about it.


 They are even described well for structures and hashes and much more.
 Be aware, though, that in general equality can be interpreted in many ways.
 At the mathematical level equality is a difficult and in many cases even an
 unsolvable thing.

Maybe, I never thought about that in mathematical terms if not with the concept
of identity. How could they do without it? Two objects (in memory) are identical
when ... no, they preferred talking about sameness. Perhaps they were right;
for each and every case you can define equality rather well. But equality as an
abstract concept may lead to a search in nothing which can take forever and 
ever:
like the moon that keeps circling around the earth without any reason one's mind
can circle around nothing. That's mighty. But that's off topic.

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Jens Axel Søgaard
2015-05-18 21:25 GMT+02:00 Michael Tiedtke michael.tied...@o2online.de:

 Il giorno 18/mag/2015, alle ore 20.50, Jos Koot ha scritto:

  I think Rackets's reference and guide are *very clear* about eq?, eqv?
 and
  equal?.

 Yes, right. It was the Racket Reference to tell me exactly that eqv? is an
 eq? that
 works for numbers and characters, too. I really had to look this up and
 found an
 simple and concise description.

 But the entries for for-each and map do not state anything about the
 execution order
 of the list processing.


Here is what the documentation say:

  Racket docs: Applies proc to the elements of the lsts from the first
elements to the last.
  R5RS: The dynamic order in which proc is applied to the elements of the
lists is unspecified.

I interpret the Racket docs to mean that the procedure are applied to the
elements in the list in the order they appear in the list.

In contrast R5RS (on purpose) state that the order is unspecified, which
means that an implementor of R5RS Scheme is free to choose the order which
fits his system best. Potentially the freedom to choose the order could
enable some optimizations.

-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Jos Koot
A fact is that equal? does not distinguish between for example two mutable
lists that happen to have the same content (whatever the same may mean)
They may be equal? at one moment and not be equal? a little bit later. With
eq? you don't have this problem, BUT that's a very distinct kind of
equality.

Jos

-Original Message-
From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com]
On Behalf Of Greg Hendershott
Sent: lunes, 18 de mayo de 2015 20:56
To: racket-users@googlegroups.com
Subject: Re: [racket-users] Strange behaviour of the eq? operator in racket
repl

In my early time learning Racket, I wish someone had given me the
following advice:


For now? Just use `equal?`.

`equal?` will usually do the right thing, including for numbers,
strings, symbols, immutable lists, and so on. A type-specific function
like `=` or `string-=?` might be a bit faster. `eq?` might be a lot
faster. But `equal?` will still be correct.

`eq?` or `eqv?` might matter semantically if you're doing certain
things -- but you're not likely to be doing them in your early days
with Racket. So if you're getting side-tracked and confused, you can
probably set it aside for now, and just use `equal?`


That advice might make some of you cringe as simplistic, but it would
have been a helpful simplification for me. And I'm talking about
modern Racket, not Schemes generally.

Of course there are also things like `egal?` that are fun to learn
about, eventually.

-- 
You received this message because you are subscribed to the Google Groups
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an
email to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Alexander D. Knauth

On May 18, 2015, at 1:19 AM, Michael Tiedtke michael.tied...@o2online.de 
wrote:

 I'm new to Racket but even R5RS is rather clear about this issue:
 
 (citation from doc/r5rs/r5rs-std/r5rs-Z-H-9.html)
 (eq? 2 2)   ===  unspecified

In Racket, (eq? 2 2) is specified as true.

It says here:
http://docs.racket-lang.org/reference/numbers.html

 A fixnum is an exact integer whose two’s complement representation fit into 
 31 bits on a 32-bit platform or 63 bits on a 64-bit platform; furthermore, no 
 allocation is required when computing with fixnums. See also the 
 racket/fixnum module, below.
 
 Two fixnums that are = are also the same according to eq?. Otherwise, the 
 result of eq?applied to two numbers is undefined, except that numbers 
 produced by the default reader in read-syntax mode are interned and therefore 
 eq? when they are eqv?.

And about symbols, they should always be eq? if they are interned, which they 
always are unless they are produced by a function like gensym or 
string-uninterned-symbol.  The symbol=? predicate uses eq? to compare the 
symbols.


-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Jos Koot
No, what you describe is not off topic at all. It is at the core of the
problem of defining what equality means.
As you already have seen, there are several definitions (and cases in which
a definition does not work)

Kind regards, Jos

-Original Message-
From: Michael Tiedtke [mailto:michael.tied...@o2online.de] 
Sent: lunes, 18 de mayo de 2015 21:26
To: Jos Koot; racket-users@googlegroups.com
Subject: Re: [racket-users] Strange behaviour of the eq? operator in racket
repl

snip

Maybe, I never thought about that in mathematical terms if not with the
concept
of identity. How could they do without it? Two objects (in memory) are
identical
when ... no, they preferred talking about sameness. Perhaps they were right;
for each and every case you can define equality rather well. But equality as
an
abstract concept may lead to a search in nothing which can take forever and
ever:
like the moon that keeps circling around the earth without any reason one's
mind
can circle around nothing. That's mighty. But that's off topic.=


-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Hendrik Boom
On Mon, May 18, 2015 at 08:50:50PM +0200, Jos Koot wrote:

 At the mathematical level equality is a difficult and in many cases even an
 unsolvable thing.

Indeed.  It is suspected by some that difficulties with equality lie at 
the root of problems with set theory.

There are two concepts of equality:

(a) equality from below, which defined two sets to be equal iff they 
have the same elements, and

(b) equality from above, which defines two sets as being equal iff they 
have the same properties.

Set theory conflates these two concepts.

Scheme has various eqialities, but they are all equalities from below.

-- hendrik

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-17 Thread Alexis King
Yes, Scheme (and therefore Racket) has eq?, eqv?, and equal?. I understand the 
desire for eq? and equal?, but I’ve always been skeptical of the necessity of 
eqv?. Either way, Scheme left this behavior unspecified, but I believe Racket 
specifies it (though I could be wrong).

Racket has two kinds of symbols, interned and uninterned. Symbols produced by 
the reader, whether via read or read-syntax, are interned. Additionally, 
string-symbol produces interned symbols. Certain functions such as gensym and 
string-uninterned-symbol produce uninterned symbols, but these are not 
commonly encountered, anyway.

Interned symbols, I believe, are guaranteed to be eq? since they’re, well, 
interned. There is a pool of interned symbols such that all symbols made up of 
the same string are all the same object, so they’re all eq?.

I can’t reproduce the behavior in the original message, and I don’t think it 
should be possible.

 On May 17, 2015, at 22:19, Michael Tiedtke michael.tied...@o2online.de 
 wrote:
 
 I'm new to Racket but even R5RS is rather clear about this issue:
 
 (citation from doc/r5rs/r5rs-std/r5rs-Z-H-9.html)
 (eq? 2 2)   ===  unspecified
 
 Rationale:   It will usually be possible to implement eq? much more 
 efficiently than eqv?, for example, as a simple pointer comparison instead 
 of as some more complicated operation. One reason is that it may not be 
 possible to compute eqv? of two numbers in constant time, whereas eq? 
 implemented as pointer comparison will always finish in constant time. Eq? 
 may be used like eqv? in applications using procedures to implement objects 
 with state since it obeys the same constraints as eqv?.
 
 
 You should use = with numbers as far as I remember.
 
 
 Il giorno 18/mag/2015, alle ore 02.41, George Neuner ha scritto:
 
 Hi,
 
 On 5/17/2015 5:32 PM, Atticus wrote:
 ---
 $ racket
 Welcome to Racket v6.1.1.
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 
 
 $ racket --no-jit
 Welcome to Racket v6.1.1.
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #t
 (eq? 'l 'l)
 #f
 (eq? 'l 'l)
 #f
 
 
 ---
 
 How to reproduce this behaviour? Just start racket from the command line
 and type '(eq? 'l 'l), this should return #f (or sometimes #t). The next
 time the same expression returns #t. Whats also interesting is that with
 the command line option --no-jit the return value seems to randomly
 change between #t and #f.   ...
 
 I can't reproduce this.  Might there have been some control characters 
 accidentally in your input?
 
 I have 6.1.1  32-bit and 64-bit on Windows 7, and 64-bit on Centos 6.6 and 
 Ubuntu 14.04.  Tried them all  with and without JIT.  Also tried the repl in 
 DrRacket on Windows (Linux are command line only).   All worked as expected.
 
 George
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Racket Users group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to racket-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Racket Users group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to racket-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-17 Thread Michael Tiedtke
I'm new to Racket but even R5RS is rather clear about this issue:

(citation from doc/r5rs/r5rs-std/r5rs-Z-H-9.html)
 (eq? 2 2)   ===  unspecified
 
 Rationale:   It will usually be possible to implement eq? much more 
 efficiently than eqv?, for example, as a simple pointer comparison instead of 
 as some more complicated operation. One reason is that it may not be possible 
 to compute eqv? of two numbers in constant time, whereas eq? implemented as 
 pointer comparison will always finish in constant time. Eq? may be used like 
 eqv? in applications using procedures to implement objects with state since 
 it obeys the same constraints as eqv?.


You should use = with numbers as far as I remember.


Il giorno 18/mag/2015, alle ore 02.41, George Neuner ha scritto:

 Hi,
 
 On 5/17/2015 5:32 PM, Atticus wrote:
 ---
 $ racket
 Welcome to Racket v6.1.1.
  (eq? 'l 'l)
 #f
  (eq? 'l 'l)
 #t
 
 
 $ racket --no-jit
 Welcome to Racket v6.1.1.
  (eq? 'l 'l)
 #f
  (eq? 'l 'l)
 #t
  (eq? 'l 'l)
 #f
  (eq? 'l 'l)
 #t
  (eq? 'l 'l)
 #t
  (eq? 'l 'l)
 #t
  (eq? 'l 'l)
 #f
  (eq? 'l 'l)
 #f
 
 
 ---
 
 How to reproduce this behaviour? Just start racket from the command line
 and type '(eq? 'l 'l), this should return #f (or sometimes #t). The next
 time the same expression returns #t. Whats also interesting is that with
 the command line option --no-jit the return value seems to randomly
 change between #t and #f.   ...
 
 I can't reproduce this.  Might there have been some control characters 
 accidentally in your input?
 
 I have 6.1.1  32-bit and 64-bit on Windows 7, and 64-bit on Centos 6.6 and 
 Ubuntu 14.04.  Tried them all  with and without JIT.  Also tried the repl in 
 DrRacket on Windows (Linux are command line only).   All worked as expected.
 
 George
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Racket Users group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to racket-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
 

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Strange behaviour of the eq? operator in racket repl

2015-05-17 Thread Atticus
Hello everyone,

So i am trying to learn scheme in my free time (unfortunately my
university doesn't use scheme in their undergraduate courses) and i was
comparing the equality operators in gambit and racket and encountered a
strange behaviour with the eq? operator in racket. To my surprise
comparing the same symbol with eq? returns sometimes a different value
in the repl. I expected the return value #t. 

This is the behaviour:

---
$ racket
Welcome to Racket v6.1.1.
 (eq? 'l 'l)
#f
 (eq? 'l 'l)
#t
 

$ racket --no-jit
Welcome to Racket v6.1.1.
 (eq? 'l 'l)
#f
 (eq? 'l 'l)
#t
 (eq? 'l 'l)
#f
 (eq? 'l 'l)
#t
 (eq? 'l 'l)
#t
 (eq? 'l 'l)
#t
 (eq? 'l 'l)
#f
 (eq? 'l 'l)
#f
 

---

How to reproduce this behaviour? Just start racket from the command line
and type '(eq? 'l 'l), this should return #f (or sometimes #t). The next
time the same expression returns #t. Whats also interesting is that with
the command line option --no-jit the return value seems to randomly
change between #t and #f.

This seems to happen only when you type the expression into the repl.

Can someone explain why the eq? operator behaves like this in the racket
repl? The eq? operator shows the expected behavior in gambit but not in
racket. Do i miss something?


Btw a big thank you to the racket team for developing, maintaining and
improving racket. Racket is awesome.

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.