Search Results

Search found 15081 results on 604 pages for 'passing by reference'.

Page 107/604 | < Previous Page | 103 104 105 106 107 108 109 110 111 112 113 114  | Next Page >

  • Prevent coersion to a single type in unlist() or c(); passing arguments to wrapper functions

    - by Leo Alekseyev
    Is there a simple way to flatten a list while retaining the original types of list constituents?.. Is there a way to programmatically construct a heterogeneous list?.. For instance, I want to create a simple wrapper for functions like png(filename,width,height) that would take device name, file name, and a list of options. The naive approach would be something like my.wrapper <- function(dev,name,opts) { do.call(dev,c(filename=name,opts)) } or similar code with unlist(list(...)). This doesn't work because opts gets coerced to character, and the resulting call is e.g. png(filename,width="500",height="500"). If there's no straightforward way to create heterogeneous lists like that, is there a standard idiomatic way to splice arguments into functions without naming them explicitly (e.g. do.call(dev,list(filename=name,width=opts["width"]))? -- Edit -- Gavin Simpson answered both questions below in his discussion about constructing wrapper functions. Let me give a summary of the answer to the title question: It is possible to construct a heterogeneous list with c() provided the arguments to c() are lists. To wit: > foo <- c("a","b"); bar <- 1:3 > c(foo,bar) [1] "a" "b" "1" "2" "3" > c(list(foo),list(bar)) [[1]] [1] "a" "b" [[2]] [1] 1 2 3 > c(as.list(foo),as.list(bar)) ## this creates a flattened heterogeneous list [[1]] [1] "a" [[2]] [1] "b" [[3]] [1] 1 [[4]] [1] 2 [[5]] [1] 3

    Read the article

  • Is it bad OOP practice to have objects reference each other?

    - by lala
    Pardon my noobness. I'm making a game in which several characters have relationships with each other and they need to be able to interact with each other and store some relationship data regarding how they feel about each other. I have an object for each character. Is it bad for each of those character objects to have an array of all the other character objects in order to perform these interactions? Is there a better way to do this?

    Read the article

  • Passing Func<T> to controller constructure when using Unity IoC with MVC, advantages?

    - by user1361315
    I was looking at a sample of how to setup Unity IoC with MVC, and noticed someone who recommended the approach of having the parameters of Func. I believe the advantage is this is kind of like lazy loading the service, if it never gets called it will never get executed and not consume any resources. private readonly Func<IUserService> _userService; public CourseController(Func<IUserService> userService) { this._userService = userService; } Versus a parameter without a Func: private readonly IUserService _userService; public CourseController(IUserService userService) { this._userService = userService; } Can someone explain to me the differences, is it really more effecient?

    Read the article

  • VB .NET Passing a Structure containing an array of String and an array of Integer into a C++ DLL

    - by DanJunior
    Hi everyone, I'm having problems with marshalling in VB .NET to C++, here's the code : In the C++ DLL : struct APP_PARAM { int numData; LPCSTR *text; int *values; }; int App::StartApp(APP_PARAM params) { for (int i = 0; i < numLines; i++) { OutputDebugString(params.text[i]); } } In VB .NET : <StructLayoutAttribute(LayoutKind.Sequential)> _ Public Structure APP_PARAM Public numData As Integer Public text As System.IntPtr Public values As System.IntPtr End Structure Declare Function StartApp Lib "AppSupport.dll" (ByVal params As APP_PARAM) As Integer Sub Main() Dim params As APP_PARAM params.numData = 3 Dim text As String() = {"A", "B", "C"} Dim textHandle As GCHandle = GCHandle.Alloc(text) params.text = GCHandle.ToIntPtr(textHandle) Dim values As Integer() = {10, 20, 30} Dim valuesHandle As GCHandle = GCHandle.Alloc(values) params.values = GCHandle.ToIntPtr(heightHandle) StartApp(params) textHandle.Free() valuesHandle.Free() End Sub I checked the C++ side, the output from the OutputDebugString is garbage, the text array contains random characters. What is the correct way to do this?? Thanks a lot...

    Read the article

  • A file is being http posted, how can I reference the parameter by index?

    - by Blankman
    An XML file is being posted to a url that my spring mvc is responding to. In .NET, I could do this: request.Form[0] request.Form["abc"] or request.QueryString[0] request.QueryString["some_key"] Now with spring/servlets it seems I can only do this: request.getParameter("some_key") or get all the names or values. When someone is posting a file to a url, using http post, won't this be just a single request parameter then? Can I get the parameter using index with servlets?

    Read the article

  • Is there a way to get a reference to all the paragraphs or headings in a web page in JavaScript?

    - by mattbd
    I'm writing a simple Greasemonkey script to strip out all the images, headings and paragraphs from a web page (it's because someone wants to use images of several popular websites with the images and text removed in a presentation about branding of websites). I've figured out how to do so with images by using a for loop and the document.images array like this: var i = 0; var imglngth = document.images.length; for(i=0;i<imglngth;i++) { document.images[i].style.display="none"; } However, I don't believe there's an object representing paragraphs or headers. Any suggestions as to how I could implement this?

    Read the article

  • How to do a back-reference on Google AppEngine?

    - by jCuga
    I'm trying to access an object that is linked to by a db.ReferenceProperty in Google app engine. Here's the model's code: class InquiryQuestion(db.Model): inquiry_ref = db.ReferenceProperty(reference_class=GiftInquiry, required=True, collection_name="inquiry_ref") And I am trying to access it in the following way: linkedObject = question.inquiry_ref and then linkedKey = linkedObject.key but it's not working. Can anyone please help?

    Read the article

  • Passing arguments to javascript file, how does it work?

    - by vietean
    From the tutorial ScriptJSONOptions of FirebugLite page, I found the below: Script JSON options It is possible to set options using a JSON object inside the linked script: <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"> { overrideConsole: false, startInNewWindow: true, startOpened: true, enableTrace: true } </script> It means that we can pass the arguments to javascript file. But I don't know how does it work? Update: My question is how to get the arguments inside the js file? P/S: I also looked into code, but I could not find the code is implemented this feature.

    Read the article

  • Why does the compiler give an ambiguous invocation error when passing inherited types?

    - by Matt Mitchell
    What is happening in the C# compiler to cause the following ambiguous invocation compilation error? The same issue applies to extension methods, or when TestClass is generic and using instance rather than static methods. class Type1 { } class Type2 : Type1 {} class TestClass { public static void Do<T>(T something, object o) where T : Type1 {} public static void Do(Type1 something, string o) {} } void Main() { var firstInstance = new Type1(); TestClass.Do(firstInstance, new object()); // Calls Do(Type1, obj) TestClass.Do(firstInstance, "Test"); // Calls Do<T>(T, string) var secondInstance = new Type2(); TestClass.Do(secondInstance, new object()); // Calls Do(Type1, obj) TestClass.Do(secondInstance, "Test"); // "The call is ambiguous" compile error }

    Read the article

  • MySQL datetime fields and daylight savings time -- how do I reference the "extra" hour?

    - by Aaron
    I'm using the America/New York timezone. In the Fall we "fall back" an hour -- effectively "gaining" one hour at 2am. At the transition point the following happens: it's 01:59:00 -04:00 then 1 minute later it becomes: 01:00:00 -05:00 So if you simply say "1:30am" it's ambiguous as to whether or not you're referring to the first time 1:30 rolls around or the second. I'm trying to save scheduling data to a MySQL database and can't determine how to save the times properly. Here's the problem: "2009-11-01 00:30:00" is stored internally as 2009-11-01 00:30:00 -04:00 "2009-11-01 01:30:00" is stored internally as 2009-11-01 01:30:00 -05:00 This is fine and fairly expected. But how do I save anything to 01:30:00 -04:00? The documentation does not show any support for specifying the offset and, accordingly, when I've tried specifying the offset it's been duly ignored. The only solutions I've thought of involve setting the server to a timezone that doesn't use daylight savings time and doing the necessary transformations in my scripts (I'm using PHP for this). But that doesn't seem like it should be necessary. Many thanks for any suggestions.

    Read the article

  • Reference properteries declared in a protocol and implemented in the anonymous category?

    - by Heath Borders
    I have the following protocol: @protocol MyProtocol @property (nonatomic, retain) NSObject *myProtocolProperty; -(void) myProtocolMethod; @end and I have the following class: @interface MyClass : NSObject { } @end I have a class extension declared, I have to redeclare my protocol properties here or else I can't implement them with the rest of my class. @interface()<MyProtocol> @property (nonatomic, retain) NSObject *myExtensionProperty; /* * This redeclaration is required or my @synthesize myProtocolProperty fails */ @property (nonatomic, retain) NSObject *myProtocolProperty; - (void) myExtensionMethod; @end @implementation MyClass @synthesize myProtocolProperty = _myProtocolProperty; @synthesize myExtensionProperty = _myExtensionProperty; - (void) myProtocolMethod { } - (void) myExtensionMethod { } @end In a consumer method, I can call my protocol methods and properties just fine. Calling my extension methods and properties produces a warning and an error respectively. - (void) consumeMyClassWithMyProtocol: (MyClass<MyProtocol> *) myClassWithMyProtocol { myClassWithMyProtocol.myProtocolProperty; // works, yay! [myClassWithMyProtocol myProtocolMethod]; // works, yay! myClassWithMyProtocol.myExtensionProperty; // compiler error, yay! [myClassWithMyProtocol myExtensionMethod]; // compiler warning, yay! } Is there any way I can avoid redeclaring the properties in MyProtocol within my class extension in order to implement MyProtocol privately?

    Read the article

< Previous Page | 103 104 105 106 107 108 109 110 111 112 113 114  | Next Page >