function

Can First-class functions in Scala be a concern for allocating a large PermGen Space in JVM?

Regarding first-class functions in Scala, it is written in the book Programming by Scala: A function literal is compiled into a class that when instantiated at run-time is a function value. When there will be many first-class functions used in a program, will this affect the JVM's PermGen space? because instead of simple functi...

How to return string from a char function

I want the function getCategory() to return "invalid" , instead of printing the word "invalid" (i.e instead of using printf ) when input to the function is invalid (i.e.when either height or weight are lower then zero). please help: #include<stdio.h> #include<conio.h> char getCategory(float height,float weight) { char invalid = '\...

How to return string from a char function

I want the function getCategory() to return "invalid" , instead of printing the word "invalid" (i.e instead of using printf ) when input to the function is invalid (i.e.when either height or weight are lower then zero). please help: #include<stdio.h> #include<conio.h> char getCategory(float height,float weight) { char invalid = '\0'; ...

PHP function won't execute when called

Hi all, I'm having a problem with this function. It's supposed to echo out some stuff, but for some reason it won't do so when I call it. Here's the function: $count = count($info['level']); function displayInfo() { for ($i=0; $i<$count; $i++) { echo "[b]".$info['name'][$i]."[/b]\n\n" ."Level: ".$info['level'][$i] ."\nP...

[Matlab] Storing Results of a Operation in a Matrix

Let's say I want to take the sin of 1 through 100 (in degrees). I come from a C background so my instinct is to loop 1 through 100 in a for loop (something I can do in Matlab). In a matrix/vector/array I would store sin(x) where x is the counter of the for loop. I cannot figure out how to do this in Matlab. Do I create a array like ...

Dynamically Auto-Linking instance variables to object functions in javascript / jquery?

Hey all, I'm trying to create a robust audio player in javascript (& jQuery). I know that there are other players out there, but I'd like to try creating my own (so please don't refer me to jquery plugins). This is essentially what I would like to do: Main.js: var player = new Player(AudioObj); // Audio object links to Audio class (n...

Should a function's comment include descriptions of work done by functions it calls?

Let's say I have a function called DisplayWhiskers() which puts some slashes and backslashes on the screen to represent an animal's whiskers like this: /// \\\. I might write a comment for this function along the lines of // Represents an animal's whiskers by displaying three // slashes followed by a space and three backslashes But ...

Why do I get 31 Dec 1969 as my last modified filename using filemtime in php ?

I am newbie to php and so please do not mind me asking this question but am really getting confused as to why filemtime(filename.txt)gives me as 31 Dec 1969 as my last modified time ? ...

Plotting functions in R

Is there a way of overlaying a mathematical function on top of data using ggplot? ## add ggplot2 library(ggplot2) # function eq = function(x){x*x} # Data x = (1:50) y = eq(x) # Make plot object p = qplot( x, y, xlab = "X-axis", ylab =...

How do you define a type for a function in Scala?

I'm hoping there is a way to define a type for a function in Scala. For example, say I want a function that takes two Ints and returns a Boolean, I could define a function that uses that like this: def checkInts(f: (Int,Int) => Boolean) = { // do stuff } Is there a way to define the type of f? Then I could do something like: def c...

jQuery: using functions from inside a plugin

hi, i wrote a little jQuery button plugin - it contains a method for applying the onclick-function - here's the code (function ($) { $.fn.tButton = function () { this.setFN = function(fn) { alert("function set."); } }; })(jQuery); i'm using this code to initialize it (on a div): var button = $("#myButton")....

Rewriting a returned pointer to an output parameter

I'm playing around with the openSSL library and it requires me to brush up on pointers, and I'm having difficulty. I have a objective-c method: -(unsigned char *)encryptTake1:(unsigned char *)input inputLength:(int)inLen outputLength:(int*)outLen; It takes some data, encrypts it and returns a pointer to the data and the length of the...

PHP: Get PHP's variables, functions, constants from a php file

Hello All, Is there a way to get user-defined php functions, variables, constants from a php file? Following functions are not the best way to do so because they get all decalred functions/vars/constants (with hundreds of php's built-in constants and internal php functions): get_defined_vars get_defined_functions get_defined_consta...

How in C# to pass a name of the object as a parameter to function?

I have the code that change the state of boolean property on mouseclick, depending on name of the clicked object: private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { FrameworkElement feSource = e.Source as FrameworkElement; switch (feSource.Name) { case "r1s1": ...

php email function

One recipient: [email protected] mail("[email protected]", "Subject: $subject", $message, "From: $email" ); If I want two recipients, can I do this: [email protected] and [email protected] mail("[email protected]", "[email protected]", "Subject: $subject", $message, "From: $email" ); ...

Alternative to returning mixed errors and booleans.

I have a (common) situation where I am currently returning a result that is a mixed type, sometimes a boolean, sometimes an error message. For example: function checked_thing_is_legal(){ // Do stuff and check for errors in here. } // Returns true if there are no errors, otherwise returns an error message string. This feels dirty, an...

How to set url parameters in an array?

Hey guys I am using open id authentication on my website and after authenticating I am getting a url from openid providers i.e yahoo and google http://www.mysite.com/openid-login.php? openid.identity=https://me.yahoo.com/a/1234567&amp; openid.ax.value.nickname=john& [email protected]& http://www.mysite.com/openid-...

Help finding out cause of misbehaving function

Hi, Sorry to bother everyone again. For some reason when I try to run the following with validateusername() nothing happens. <script language="javascript"> //<----------------------------------+ // Developed by Roshan Bhattarai and modified by Harry Rickards // Visit http://roshanbh.com.np for the origional version of this script an...

Define two functions, or branch within one?

I was reading about how to detect the encoding of a file in PHP, and on some blog or somewhere, it was suggested to do this: if (function_exists('mb_detect_encoding')) { function is_utf8($str) { // do stuff using the mb* libraries } } else { function is_utf8($str) { // do stuff manually } } To me this f...

Is there a lower limit and upper limit check function in PHP or MySQL?

Is there such a function in PHP or MySQL? function check($lower,$val, $upper) { if ($val>$lower && $val<$upper) { return $val; } if ($val<=$lower) { return $lower; } if ($val>=$upper) { return $upper; } } ...