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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:25:30+00:00 2026-05-17T02:25:30+00:00

Suppose a function f() returns a value of arbitrary type, perhaps an object but

  • 0

Suppose a function f() returns a value of arbitrary type, perhaps an object but possibly even a builtin type like int or list. Is there a way to assign a variable to that return value, and have a function of my choosing be called the first time the variable is used?

I suppose this is similar to lazy evaluation except that a reference to x exists and can be used by subsequent code.

It might look like this:

x = f() # f is a function, assign variable to return value, but return value is unknown

# do something arbitrary with x
return str(x) # this calls a callback attached to x, which returns the value of x to be used

Again, I want to do this on any type, not just an object instance.

  • 1 1 Answer
  • 3 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-17T02:25:31+00:00Added an answer on May 17, 2026 at 2:25 am

    If you want to write a C extension for it, you could wrap the value in something that behaves the way that Python’s weakref.ProxyType does, only with laziness instead of “weak”ness. You can always take a look at the Python source code to see how that’s done but something tells me it’s nontrivial.

    The implementation of the weakref proxy type in Python is here.

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

Sidebar

Related Questions

Suppose I'm writing a function that takes a list of integers and returns only
Suppose I need to implement factory function which returns object O which inherits/has members
Suppose I write a function that takes no input but returns random variable e.g.,
Suppose we want to return a value from a function based on a condition.
Suppose I have an array of values [a,b,c,d,...] and a function f(x,...) which returns
Suppose I have a function that returns a closure: sub generator { my $resource
Suppose that you have a function f: List a -> a such that f
Suppose I have a utility function like this - public static boolean isABlankSpace(char c)
Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*
Suppose I have a function like this (I use akka 2.0.2): def foo(message: String):

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.