Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 418711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:42:20+00:00 2026-05-12T18:42:20+00:00

I am trying to compare two strings in Smalltalk, but I seem to be

  • 0

I am trying to compare two strings in Smalltalk, but I seem to be doing something wrong.

I keep getting this error:

Unhandled Exception: Non-boolean receiver. Proceed for truth.

stringOne := 'hello'.
stringTwo := 'hello'.
myNumber := 10.

[stringOne = stringTwo ] ifTrue:[
   myNumber := 20].

Any idea what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:42:20+00:00Added an answer on May 12, 2026 at 6:42 pm

    Try

    stringOne = stringTwo 
         ifTrue: [myNumber := 20]`
    

    I don’t think you need square brackets in the first line

    Found great explanation. Whole thing is here

    In Smalltalk, booleans (ie, True or False) are objects: specifically, they’re instantiations of the abstract base class Boolean, or rather of its two subclasses True and False. So every boolean has type True or False, and no actual member data. Bool has two virtual functions, ifTrue: and ifFalse:, which take as their argument a block of code. Both True and False override these functions; True’s version of ifTrue: calls the code it’s passed, and False’s version does nothing (and vice-versa for ifFalse:). Here’s an example:

    a < b
      ifTrue: [^'a is less than b']
      ifFalse: [^'a is greater than or equal to b']
    

    Those things in square brackets are essentially anonymous functions, by the way. Except they’re objects, because everything is an object in Smalltalk. Now, what’s happening there is that we call a’s “<” method, with argument b; this returns a boolean. We call its ifTrue: and ifFalse: methods, passing as arguments the code we want executed in either case. The effect is the same as that of the Ruby code

    if a < b then
      puts "a is less than b"
    else
      puts "a is greater than or equal to b"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compare two strings with each other on the iphone, but the
I am trying to compare two strings in VB but compareTo, compare, equals etc
I am trying to compare two strings in a simple shell script. I was
I'm trying to compare two strings. When I echo them, they appear to be
I'm trying to compare two strings. One stored in a file, the other retrieved
I am trying to compare two strings and remove any characters that appear in
I'm trying to use simpletest to compare two numeric strings, one from an array
I am trying to compare two decimal values in Java script. I have two
Trying to keep all the presentation stuff in the xhtml on this project and
What I need to do is compare two strings and mark the differences with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.