Search Results

Search found 38817 results on 1553 pages for 'inline function'.

Page 77/1553 | < Previous Page | 73 74 75 76 77 78 79 80 81 82 83 84  | Next Page >

  • how am I supposed to call the function?

    - by user1816768
    I wrote a program which tells you knight's movement (chess). For example if I wanted to know all possible moves, I'd input: possibilites("F4") and I'd get ['D3', 'D5', 'E2', 'E6', 'G2', 'G6', 'H3', 'H5'] as a result, ok I did that, next, I had to write a function in which you input two fields and if those fields are legal, you'd get True and if they're not you'd get False(I had to use the previous function). For example: legal("F4","D3") >>>True code: def legal(field1,field2): c=possibilities(field1) if field1 and field2 in a: return True return False I'm having a problem with the following function which I have to write: I have to put in path of the knight and my function has to tell me if it's legal path, I'm obliged to use the previous function. for example: >>> legal_way(["F3", "E1", "G2", "H4", "F5"]) True >>> legal_way(["F3", "E1", "G3", "H5"]) False >>> legal_way(["B4"]) True I know I have to loop through the list and put first and second item on it in legal(field1,field2) and if it's false, everything is false, but if it's true I have to continue to the end, and this has to work also if I have only one field. I'm stuck, what to do? def legal_way(way): a=len(way) for i in range(0,a-2): if a==1: return true else if legal(way[i],way[i+1]: return True return False and I get True or index out of range

    Read the article

  • Adding a wrapper to an overloaded function

    - by Cev
    Say you had a timestamp function and then wanted to create a new function to combine your timestamp and Console.WriteLine(), e.g. public static void Write(string msg) { WriteTimeStamp(); Console.WriteLine( msg ); } But the WriteLine() method has 18 or so overloads, which will not be reflected in the signature of the wrapper function. How would you have the wrapper take non-strings and pass them on to WriteLine()?

    Read the article

  • how to view associated click function code

    - by llamerr
    For example, i associate following function with some element $('table#users tbody tr:first #save').click(function(){ $(this).closest('tr').remove(); }); Now, if i don't know where this function is stored, is there a way to view associated with click() code? In above example, i want a way to view that in firebug, or in another way $(this).closest('tr').remove(); If I'm writing in console following, i'm get a link to dom inspector >>> ($('table#users tbody tr:first #save').click) function() but link is for jquery library, not the code i want.

    Read the article

  • Accessing loop iteration in a sub-function?

    - by DisgruntledGoat
    I'm using the Google Maps API to plot several points on a map. However, in the click event function below, i is always set to 4, i.e. its value after iterating the loop: // note these are actual addresses in the real page var addresses = new Array( "addr 1", "addr 2", "addr 3", "addr 4" ); for (var i = 0; i < addresses.length; i++) { geocoder.getLatLng(addresses[i], function(point) { if (point) { var marker = new GMarker(point); map.addOverlay(marker); map.setCenter(point, 13); GEvent.addListener(marker, "click", function() { // here, i=4 marker.openInfoWindowHtml("Address: <b>" + addresses[i] + "</b>"); }); } }); } So when the marker displays it's using addresses[4] which is undefined. How do I pass the correct value of i to the function?

    Read the article

  • Trying to make a reusable function and display the result in a div

    - by user3709033
    I have this function that I am trying to work with. All I am trying to do is to get the values of days, hours, min and sec into the .overTime div. I want to use the same function over and over again because i have more divs in which I want to display the same values but in a diff manner. You guys are awesome Thank You. NowTime = new Date(); //Time Now StartTime = new Date($('#StartTime').val()); StopTime = new Date($('#StopTime').val()); function fixIntegers(integer){ if (integer < 0) integer = 0; if (integer < 10) return '0' + integer; return '' + integer; } function Test( difference ) { var toReturn = { days: 0, hours: 0, minutes: 0, seconds: 0 }; toReturn.seconds = fixIntegers(difference % 60); difference = Math.floor(difference / 60); toReturn.minutes = fixIntegers(difference % 60); difference = Math.floor(difference / 60); toReturn.hours = fixIntegers(difference % 24); difference = Math.floor(difference / 24); toReturn.days = fixIntegers(difference); return toReturn; } function run() { var output = Test( Math.floor( ( NowTime - StopTime ) / 1000 ) ); $('.OverTime').html( output.days + ':' + output.hours + ':' + output.minutes + ':' + seconds); } setInterval(run, 1000) FIDDLE: http://jsfiddle.net/8943U/47/

    Read the article

  • How can I use edit_in_place in the show of a different model in Rails?

    - by Angela
    I have a model Campaign and the campaign/show goes through a loop of the Emails. Campaign has_many Emails. <h2>Emails to Send Today</h2> <% for email in @campaign.emails %> <p><strong>Email: </strong><%= link_to email.title, email_path(email) %> sent after <%= distance_of_time_in_words(email.days.days) %></p> <% end %> I would like to be able to edit in place the subject and/or the email.days value from the Campaign/show page. How do I do that? (Added complexity, these are clickable links).

    Read the article

  • JavaScript function to validate an integer value

    - by Psyche
    Hello, I'm building a shopping cart and I would like to use a JavaScript function to validate user input when entering the quantity value in the quantity text input. I would like to allow the entering of integer values only (no floats, no other characters). I know that I can apply this function using onKeyUp event and also I found isNaN() function, but it returns true even for floats (which is not ok). Can you guys help me out with this one? Thanks.

    Read the article

  • Strange C++ thread function invocation

    - by Tony
    I have the following: class DThread { virtual void run()=0; _beginthreadex(NULL,0,tfunc,this,0,&m_UIThreadID); // class itself being passed as param to thread function... static unsigned int __stdcall tfunc(void* thisptr) { static_cast<DThread*>(thisptr)->run(); return 0; } //other stuff } The run function is implemented in a derived class. Why is the function that's being called in the thread being called through a cast this pointer? Is this good practise? Can't it just be called directly? The actual function needing to run is in the derived class. My question is

    Read the article

  • Haskell Binary Tree Function (map)

    - by Bizarro
    How can i define a Haskell function which will apply a function to every value in a binary tree? So i know that it is similar to the map function - and that its type would be: mapT :: (a - b) - Tree a - Tree b but thats about it...

    Read the article

  • F# - Function with no arguments?

    - by Rubys
    When thinking in a functional mindset, given that functions are supposed to be pure, one can conclude any function with no arguments is basically just a value. However, reallity gets in the way, and with different inputs, I might not need a certain function, and if that function is computationally expensive, I'd like to not evaluate it if it's not needed. I found a workaround, using let func _ = ... and calling it with func 1 or whatever, but that feels very non-idiomatic and confusing to the reader. This boils down to one question: In F#, Is there a proper way to declare a function with zero arguments, without having it evaluated on declaration?

    Read the article

  • Getting the callers of a specific function

    - by robUK
    Hello, GNU Emacs 23.1.1 I am just wondering is there any feature in emacs where I can find out what functions call a specific function. In my code, I normally have to do a search on the function name to see what functions calls it. It would be nice if I could display all the names of the functions where this specific function is being called from. many thanks for any suggestions,

    Read the article

  • AS3: Performance question calling an event function with null param

    - by adehaas
    Lately I needed to call a listener function without an actual listener like so: foo(null); private function foo(event:Event):void { //do something } So I was wondering if there is a significant difference regarding performance between this and using the following, in which I can prevent the null in calling the function without the listener, but am still able to call it with a listener as well: foo(); private function foo(event:Event = null):void { } I am not sure wether it is just a question of style, or actually bad practice and I should write two similar functions, one with and one without the event param (which seems cumbersome to me). Looking forward to your opinions, thx.

    Read the article

  • pointer to preallocated memory as an input parameter and have the function fill it

    - by djones2010
    test code: void modify_it(char * mystuff) { char test[7] = "123456"; //last element is null i presume for c style strings here. //static char test[] = "123123"; //when i do this i thought i should be able to gain access to this bit of memory when the function is destroyed but that does not seem to be the case. //char * test = new char[7]; //this is also creating memory on stack and not the heap i reckon and gets destroyed once the function is done with. strcpy_s(mystuff,7,test); //this does the job as long as memory for mystuff has been allocated outside the function. mystuff = test; //this does not work. I know with c style strings you can't just do string assignments they have to be actually copied. in this case I was using this in conjunction with static char test thinking by having it as static the memory would not get destroyed and i can then simply point mystuff to test and be done with it. i would later have address the memory cleanup in the main function. but anyway this never worked. } int main(void) { char * mystuff = new char [7]; //allocate memory on heap where the pointer will point cool(mystuff); std::string test_case(mystuff); std::cout<<test_case.c_str(); //this is the only way i know how to use cout by making it into a string c++ string. delete [] mystuff; return 0; } in the case, of a static array in the function why would it not work. in the case, when i allocated memory using new in the function does it get created on the stack or heap? in the case, i have string which needs to be copied into a char * form. everything i see usually requires const char* instead of just char*. I know i could use reference to take care of this easy. Or char ** to send in the pointer and do it that way. But i just wanted to know if I could do it with just char *. Anyway your thoughts and comments plus any examples would be very helpful.

    Read the article

  • Why does this C program compile?

    - by AdmiralJonB
    I've just come across someone's C code that I'm confused as to why it is compiling. There are two points I don't understand. First, the function prototype has no parameters compared to the actual function definition. Secondly, the parameter in the function definition doesn't have an type. #include <stdio.h> int func(); int func(param) { return param; } int main() { int bla = func(10); printf("%d",bla); } Could someone please explain to me why this works? I've tested it in a couple of compilers and it works fine.

    Read the article

  • VB6: assign javascript function to a dom element

    - by Fuxi
    hi, i'm using the mshtml library for parsing out html via MSHTML.HTMLDocument. my question: is there a way to assign a javascript function to a dom element? i've tried something like: div.onmouseover = "function(){alert('mouseover')}" and div.setattribute "onmouseover" , "function(){alert('mouseover')}" without success (no error but no effect either). anyone knows if its possible? thx

    Read the article

  • JQuery selector: pass on id from array into function

    - by user347256
    I have a list of items <div id="item1">somestuff</div> <div id="item2">somestuff</div> <div id="item3">somestuff</div> When someone clicks on one of these, I need to take some actions based on the id (the number). Let's say hide it. How can I make the function generic, and how can I pass the id into the function? $(document).ready(function() { $("#item-howcanImakethisselectorgeneric?").click(function () { $("#item-andhowcanIpasshteidintohere?").hide(); } } I'm a javascript/jquery newbie, any help (including rtfm) appreciated.

    Read the article

  • Passing arguments to a function?

    - by dfjhdfjhdf
    I need to learn how to pass an associative array to a function so that I could do the following within the function: function someName($argums) { if (gettype($argums) != 'array' || !array_key_exists('myOneKey', $argums) || !array_key_exists('myOtherKey', $argums)) { return false; } /*do other stuff*/ } (That's how I would do in PHP what I am looking for in JavaScript.)

    Read the article

  • PowerShell function won't return object

    - by Dan
    I have a simple function that creates a generic List: function test() { $genericType = [Type] "System.Collections.Generic.List``1" [type[]] $typedParameters = ,"System.String" $closedType = $genericType.MakeGenericType($typedParameters) [Activator]::CreateInstance($closedType) } $a = test The problem is that $a is always null no matter what I try. If I execute the same code outside of the function it works properly. Thoughts?

    Read the article

  • Force to reimplement a static function in inherit classes

    - by pacopepe
    Hi, I have a program in C++ with plugins (dynamic libs). In the main program, I want to execute a static function to check if i can create a object of this type. An example without dynamic libs (aren't neccesary to understand the problem): #include "libs/parent.h" #include "libs/one.h" #include "libs/two.h" int main(int argc, char * argv[]) { Parent obj; if (One.match(argv[1])) { obj = new One(); else if (Two.match(argv[1])) { obj = new Two(); } Now, i have a interface class named Parent. All plugins inherit from this class. Ideally, I have a virtual static function in Parent named match, and all the plugins need to reimplement this function. The problem with this code is that i can't do a static virtual function in C++, so i don't know how to solve the problem. Sorry for mi english, i did my best

    Read the article

  • How to access function inside PHP OOP

    - by Industrial
    Hi everyone, What do I need to do to call $this-two() from inside my function innerOne? Is that possible with PHP OOP? Here's the error I am recieving: Fatal error: Using $this when not in object context Here's how my code looks: class myClass { function one(){ function innerOne() { // Some code $this->two($var1, $var2); } // Some code innerOne(); } function two($var1, $var2) { // Does magic with passed variables return $var1 . $var2; } } Thanks a lot!

    Read the article

  • Make get function Sycronous / Javascript

    - by DDL449
    I'm experiencing a problem of $.get function. The url contains JSON this is my code: xyz = null $.get('http://www.someurl.com/123=json', function(data) { var xyz = data.positions[0].latitude; }); alert(xyz); //some more code using xyz variable I know that xyz will alert a null result because the $.get is asychronous. So is there any way I can use the xyz outside this get function? Thank you

    Read the article

< Previous Page | 73 74 75 76 77 78 79 80 81 82 83 84  | Next Page >