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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:19:46+00:00 2026-06-18T05:19:46+00:00

I am concerned about writing self-modifying code in Ruby. And by self-modifying, I mean

  • 0

I am concerned about writing self-modifying code in Ruby. And by self-modifying, I mean being able to write functions that take a code block as an input value, and output another code block based on this. (I am not asking about basics such as redefining methods at runtime.)

What I might want to do is, for example, having the following block,

_x_ = lambda { |a, b, c, d| b + c }

one can notice that arguments a and d are not used in the body at all, so I would like a function eg. #strip to remove them,

x = _x_.strip

which should produce same result as writing:

x = lambda { |b, c| b + c }

Now in Lisp, this would be easy, since Lisp code is easily manipulable data. But I do not know how to manipulate Ruby code. I can parse it eg. by

RubyVM::InstructionSequence.disassemble( x )

But how, based on this, do I write a modified block? Other examples of what I would want to do are are eg.

y = lambda { A + B }
y.deconstantize
# should give block same as saying
lambda { |_A, _B| _A + _B }

So far, in Ruby, I have never encountered a situation where I had to concede that something is not possible. But this time, gut feeling tells me that I might have encountered the fundamental weakness of beautifully structured code vs. code with little syntax to speak about (which would be Lisp). Please enlighten me.

  • 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-18T05:19:47+00:00Added an answer on June 18, 2026 at 5:19 am

    Boris do you necessarily have to rely on Ruby to begin with here?

    Why not just create your own situation-specific language that the chemists can use just for the purpose to express their formulas in the most convenient way. Then you create a simple parser and compiler for this “chemical expression language”.

    What I mean is this parser and compiler will parse and compile the expressions the chemists write in their Ruby code. Then you could have:

    ChemicalReaction.new(..., "[ATP] * [GDP] * NDPK_constant")
    

    Voila: ultimate flexibility.

    That’s the approach I would take if usability is your main concern. Already writing out “lambda” seems like an unnecessarily cumbersome thing to me here, if all you want to do is express some domain-specific formula in the most compact way possible.

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

Sidebar

Related Questions

I'm writing a function in x86 assembly that should be callable from c code,
I'm writing a Chrome extension and I'm specifically concerned about the HTML layout in
I just read an article in the BlackBerry docs about writing efficient code in
I'm writing a script that needs to write the current page location to the
I'm writing the code for a GUI (in C++), and right now I'm concerned
I have almost finished writing my app, and i am concerned about the app
I'm new to writing Windows Services. I decided to write one that makes outbound
I'm writing an app with a MySQL table that indexes 3 columns. I'm concerned
I'm concerned about the performance of the query below once the tables are fully
I'm currently building a Jython web app but am concerned about Jython application performance.

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.