anonymous

Why would I use Perl anonymous subroutines instead of a named one?

点点圈 提交于 2019-11-28 07:33:06
I'm just curious why one would choose to use an anonymous subroutine, versus a named one, in Perl. Thanks. innaM You can store anonymous subs in arrays, hashes and scalars. You can build them at runtime You can pass them as arguments to other functions. You get to keep variables in the surrounding scope. The last point is probably the most important, because it's often the most unexpected facet of named vs. anonymous subroutines in Perl. Example: sub outer { my $a = 123; sub inner { print $a, "\n"; } # At this point, $a is 123, so this call should always print 123, right? inner(); $a = 456; }

Setting anonymous type property name

被刻印的时光 ゝ 提交于 2019-11-28 02:30:41
问题 Let's say I have the following piece of code: string SomeConst = "OtherName"; var persons = GetPersons(); //returns list of Person var q = persons.Select(p => new { SomeConst = p.Name }); Basically I'd expect to have in q sequence of anonymous type with the property named OtherName and not SomeConst . How can I achieve such a behaviour? 回答1: You can't do that. The names of the properties of an anonymous type must be known at compile time. Why exactly do you need to do that? You could achieve

initialization of anonymous structures or unions in C1X

那年仲夏 提交于 2019-11-27 21:13:22
问题 I have the following question: How are anonymous structures (or unions) properly initialized according to the current C1X draft? Is this legal: struct foo { int a; struct { int i; int j; }; int b; }; struct foo f = { 1, 2, 3, 4 }; struct foo g = { 1, { 2 }, 3 }; In GCC, g.j == 0 and g.b == 3 , while in tcc g.j == 3 and g.b == 0 . The current draft says: "[...] unnamed members of objects of structure and union type do not participate in initialization. Unnamed members of structure objects have

What is the difference between anonymous and inline functions in JavaScript? [closed]

烈酒焚心 提交于 2019-11-27 19:49:40
The title sums up my question. An example that demonstrates the point would be nice. Daniel Gimenez First off, there doesn't seem to be a consensus definition for inline functions in JavaScript. I consider an inline function to be a special case of a JavaScript function. An inline function is a function assigned to a variable that is created at runtime instead of at parsetime. Anonymous functions and inline functions are practically the same, in that they are created at runtime. The difference is that an inline function is assigned to a variable and so it can be reused. In that way, inline

WCFTestClient The HTTP request is unauthorized with client authentication scheme 'Anonymous'

早过忘川 提交于 2019-11-27 18:55:34
I've created one WCF service and deployed it on Server. When I browse this service it gives me positive response with ?wsdl URL. Now I'm trying to test the service through WCF Test client. It shows proper metadata. But when I try to invoke any of the method from the service it shows me an exception... here are the erro details with stack trace.. The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'. Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication

How can I identify an anonymous inner class in a NotSerializableException

拜拜、爱过 提交于 2019-11-27 16:09:13
I have received the following error message when trying to debug an application in NetBeans: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: board.Board$1 In the course of debugging I have had to insert 'implements Serializable' in a number of classes as the exception arose in the course of reading from a file that stores a large object. This has not been difficult as the class needing attention has been clear from the exception message. What has thrown me is the apparent anonymous inner class 'Board$1'. I can't for the life of me identify the source with

Linkage of symbols within anonymous namespace within a regular namespace

烂漫一生 提交于 2019-11-27 13:07:29
问题 In C++, putting a function or a variable in an anonymous namespace makes its linkage internal, i. e. the same as declaring it static on a file-level, but idiomatic C++. What about an anonymous namespace within a normal namespace? Does it still guarantee internal linkage? // foo.cpp void func1() { // external linkage } static void func2() { // internal linkage } namespace { void func3() { // internal linkage } } namespace ns1 { void func4() { // external linkage } namespace { void func3() { //

How to create an instance of anonymous interface in Kotlin?

余生颓废 提交于 2019-11-27 11:45:27
I have a third party Java library which an object with interface like this: public interface Handler<C> { void call(C context) throws Exception; } How can I concisely implement it in Kotlin similar to Java anonymous class like this: Handler<MyContext> handler = new Handler<MyContext> { @Override public void call(MyContext context) throws Exception { System.out.println("Hello world"); } } handler.call(myContext) // Prints "Hello world" Assuming the interface has only a single method you can make use of SAM val handler = Handler<String> { println("Hello: $it")} If you have a method that accepts

How to contribute on github anonymously via Tor?

試著忘記壹切 提交于 2019-11-27 09:59:42
问题 I would like to contribute anonymously to projects on github. Not to cause mischief, more in the spirit of anonymous donations. The tool of choice for being anonymous online seems to be TOR, which works well for almost anything you can do in a browser. However, to contribute on github, it appears necessary to use the command line interface, or the Mac app. How can I channel my git operations in this setup through Tor? And how can I verify that this is actually what is happening? Edit: please

C++11 anonymous union with non-trivial members

感情迁移 提交于 2019-11-27 07:06:30
I'm updating a struct of mine and I was wanting to add a std::string member to it. The original struct looks like this: struct Value { uint64_t lastUpdated; union { uint64_t ui; int64_t i; float f; bool b; }; }; Just adding a std::string member to the union, of course, causes a compile error, because one would normally need to add the non-trivial constructors of the object. In the case of std::string (text from informit.com) Since std::string defines all of the six special member functions, U will have an implicitly deleted default constructor, copy constructor, copy assignment operator, move