There exists anonymous function, and you could also use a variable to
contain such function. But why no class?
I mean, you could do:
$func = create_function ('$a', 'print $a;');
$func();
or
function test($a)
{
print $a;
}
$func = 'test';
call_user_func( $func, xx);
But there is no:
$class = create_class('' , '');
or
$class = 'MyClass';
class $class {}
Why? 1 1260
Sorry, I paste wrong forum?
Could someone move it to comp.lang.php?
Yarco
There exists anonymous function, and you could also use a variable to
contain such function. But why no class?
I mean, you could do:
$func = create_function ('$a', 'print $a;');
$func();
or
function test($a)
{
print $a;
}
$func = 'test';
call_user_func( $func, xx);
But there is no:
$class = create_class('' , '');
or
$class = 'MyClass';
class $class {}
Why?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Doug Holton |
last post by:
Is there any metaclass trick or something similar to allow anonymous
code blocks?
I'd like to be able to let users do something like this fictitious example:
b = Button()
b.OnClick =:
print "you clicked me"
But that would require adding a special "=:" operator to bind a code
block to a function.
|
by: Carlos Ribeiro |
last post by:
I thought about this problem over the weekend, after long hours of
hacking some metaclasses to allow me to express some real case data
structures as Python classes. I think that this is something with
potential to be useful, but I would like to hear more opinions first.
If this is deemed to be useful, I *may* try to write a PEP for it.
This is not a promise or even a proposal, at this point.
Broadly generalizing, classes in Python have...
|
by: Mark Brandyberry |
last post by:
I have a bit of a problem with an overloaded operator that I'm writing that
I have distilled down to an example in the code below. Essentially, I have
an operator function (+=) that takes a reference parameter of class Poly.
If I use it with a named object (of type Poly), as in:
P1+=P4;
where P1 and P4 are both local variables of the class type, it works fine.
If I try to use an anonymous object on the right side, then I get an error...
|
by: Cordell Lawrence |
last post by:
Okay guys,
We are wondering if this is a bug in Framework 2.0.40607 and
looking for some clarification on the issue. Take a look at the folowing
code.
public delegate bool BoundryTest(int myVal);
|
by: d225563 |
last post by:
I read an article that had a really elegant solution to pass parameters
to a thread by using an anonymous method as your ThreadStart. It
seemed pretty slick and even worked when I tried it. However, with
some more playing around, I got some really strange results. Using the
code below, sometimes my output is 2 and 3. Sometimes, it's 3 and 3.
However, it's never been 1 and 2 which is what I would expect. Can
anybody set me straight on...
| |
by: Gaijinco |
last post by:
I have always felt that there are a lot of topics that you learned the
facts but you only grasp the matter sometime down the road.
For me, two of those topics are inner classes and anonymous classes.
I was thinking of a class Agenda. For it I would use a class Person
which also uses another class Date for her birthday.
When I was modeling Person, I made an atribute to be an object of
class Date. Suddenly I thought that maybe it was a...
|
by: =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?= |
last post by:
Hi,
I need to initialize my class level dictionary (in .Net 2.0). I wanted to
make it inline and employ anonymous methods as I do not use this code for
anything else. Something similar to the following:
private static Dictionary<string, field_fields = delegate()
{
Dictionary<string, fieldresult = new Dictionary<string, field>();
result.Add("Application", new field("Application", "AppName"));
|
by: Frankie |
last post by:
I have just gotten up to speed on what anonymous methods are (syntax,
capabilities, etc), and how they can be used with /called via delegates.
What I am wondering is...
1. Are they only/mostly syntactic sugar (important as that can be)?
2. Are anonymous methods *required* anywhere? That is, are anonymous methods
the only way to accomplish certain tasks in
..NET programming?
|
by: Tony |
last post by:
Hello!
Here I have some text from a book I read. It says:
"An interesting point to note concerning anonymous methods is that they are
effectively local to the code
block that contains them, and they have access to local variables in this
scope. If you use such a variable
it becomes an outer variable. Outer variables are not disposed of when they
go out of scope like other
local variables are; instead, they live on until the anonymous...
|
by: Tim Chase |
last post by:
I've got code similar to the following
class Action:
def __init__(self, ...): pass
def __call__(self, ...): pass
def get_help(self, ...): pass
class Backend:
class _Load(Action):
def __init__(self, ...): pass # override1
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |