-1

I am running following code:

(define  myframe  (new frame% [label "myframe"]))

(define tf1 (new text-field%  [parent myframe] [label "tf1"]))
(define tf2 (new text-field%  [parent myframe][label "tf2"]))
(define tf3 (new text-field%  [parent myframe][label "tf3"]))

(send  myframe show #t)

(define combined_str (string-append (send tf1 get-value) "-" (send tf2 get-value) "-" (send tf3 get-value) )) 
(println combined_str)
(if (eq? "--" combined_str) "same" "different")

Output is:

"--"
"different"

The combined_str is "--" because the text-fields are blank. But it is not coming as same as "--".

rnso
  • 23,686
  • 25
  • 112
  • 234
  • Possible duplicate of [What is the difference between eq?, eqv?, equal?, and = in Scheme?](http://stackoverflow.com/questions/16299246/what-is-the-difference-between-eq-eqv-equal-and-in-scheme) (Since these operators in Racket are compatible with Scheme standard) – Sylwester Aug 13 '16 at 21:35

1 Answers1

4

This is almost certainly caused by using eq? instead of equal?. See Object Identity and Comarpison for more, and also What is the difference between eq?, eqv?, equal?, and = in Scheme?. In short, eq? does a pointer comparison, which isn't what you want.

Examples:

> (eq? "--" (string-append "-" "-"))
#f
> (equal? "--" (string-append "-" "-"))
#t
> (string=? "--" (string-append "-" "-"))
#t
Community
  • 1
  • 1
Gibstick
  • 727
  • 5
  • 7