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 7884383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:47:06+00:00 2026-06-03T04:47:06+00:00

I have an object, and a string containing a message I would like to

  • 0

I have an object, and a string containing a message I would like to send to it.

For example, the string ‘+ 5’, which I would like to send to some integer object.

If it was in the workspace then I would just write “obj + 5”, but I need it to be done at running time without knowing the string in advance…

  • 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-06-03T04:47:08+00:00Added an answer on June 3, 2026 at 4:47 am

    If you can separate the argument of the message from the message itself, then you can “perform” the message send:

    obj := 3.
    msg := '+'.
    arg := 5.
    result := obj perform: msg asSymbol with: arg.
    

    Otherwise, you would have to use the Compiler, which would translate the string into compiled code and execute it:

    obj := 3.
    msg := 'self + 5'.
    result := Compiler evaluate: msg for: obj logged: false.
    

    A common technique to avoid repeated compilation is to compile a block, which can be evaluated more efficiently:

    obj := 3.
    msg := '[:x | x + 5]'.
    block := Compiler evaluate: msg.
    result := block value: obj.
    

    Btw, the code above (and below) is for Squeak, other Smalltalks may have a different way to access the Compiler.

    There is an even more hackish way that lets you access the variable directly from the string. This is by executing the compiled code in “thisContext” (in this case you need to declare the temp vars even in a workspace):

    | obj msg result |
    obj := 3.
    msg := 'obj + 5'.
    result := Compiler new evaluate: msg in: thisContext to: nil.
    

    However, I would not recommend this last technique. Performing is generally safer than involving the Compiler. That said, it can be used to implement some serious meta stuff. E.g.:

    | obj |
    obj := 3.
    'The result is {obj + 5}.' expand
    

    Implementation of the “expand” method is left to the curious reader 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml.dom.Element object and would like to convert it to a string
I have a Django Queryset object called data containing string keys and float values.
I have a ComboBox with a label function like this one: private function fieldLabelFunction(item:Object):String
I have a php string containing the serialization of a javascript object : $string
Assuming you have a string containing the name of a method, an object that
I have a JSON object containing a number of strings. I also have a
I have a String Object in format yyyyMMdd .Is there a simple way to
I have an object with a string[] property. When I assign this as the
I have a C# string object that contains the code of a generic method,
I have this object: class a { public string Application; public DateTime From, To;

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.