function

How to make clear to user that the function's argument to be entered as string in Matlab?

I have the following function whose last argument is a name of the text file: function [property_without_headers]=gslib_file_to_matlab_var(nModel,nCell,gslib_file_name) % must enter the last argument, gslib_file_name, in single quotes as its treated as a string if nargin<3, % making third argument optional (code to be executed even whe...

Python equivalent of ActionScript 3's restParam

In ActionScript 3 (Flash's programming language, very similar to Java - to the point that it's disturbing), if I was defining a function and wanted it to be called with endless parameters, I could do this (restParam, I thought it was called): function annihilateUnicorns(...unicorns):String { for(var i:int = 0; i<unicorns.length; i++...

How to map a tuple of data to a tuple of functions?

I have the following Python code: data = ['1', '4.6', 'txt'] funcs = [int, float, str] How to call every function with data in corresponding index as an argument to the function? Now I'm using the code: result = [] for i, func in enumerate(funcs): result.append(func(data[i])) map(funcs, data) don't work with tuple of function...

How to Check whether the function is called for the last time in PHP

Hello, I Want to check whether a function is called for the last time. Consider the following sample code, function foo(){ if( this is the last call ) { echo 'this is the last call of this function'; } } foo(); // should not print foo(); // should not print foo(); // since this is the last call, it should print In ...

Doing something before program exit

How can you have a function or something that will be executed before your program quits? I have a script that will be constantly running in the background, and I need it to save some data to a file before it exits. Is there a standard way of doing this? ...

Javascript arguments as array?

so I have a button with this event: onmousedown="hideElements('\x22cartview\x22,\x22other\x22')" and then this function hideElements: function hideElements(what) { var whichElements=[what]; alert(whichElements[0]); } I want it to alert "cartview" but it alerts "cartview","other" I am aware of the arguments object ...

php :: shorten this function? :: array manipulation

Hi guys, So I have a function as detailed below, I believe it is too long and can be shortened. I think I have fallen over in the array manipulation part. Please ignore the strange database syntax So basically this function is given a string like this abc, def, ghi, jkl, mno due to some glitches it can be received with an extra...

How do I make a function return the result of multiple variable types in C?

Just started learning C from Cocoa developing guide and I was wondering how (if at all possible) I would return the result of a function with multiple variable types. For example, I have a simple math function that I made to practice what I am reading and I gave it multiple variable types: #include <stdio.h> float doMath (int variable...

Call parent function in xcode iphone development

We have 2 files 'MainViewController' and 'View01' The first file addSubView the second one. In the first file we have a function named displayView. I want to be able to call this function from the View01 file is the following code correct part of View01 file #import "MainViewController.h" - (IBAction) changeView:id(sender){ Ma...

matlab: quick function that can produce NaN if x > 1

I am looking for a one-line function f = @(x) {something} that produces NaN if x >= 1, and either 0 or 1 if x < 1. Any suggestions? ...

Ambiguous declarations

What is the difference between the following two declarations: 1. int foo(int); 2. int foo(int()); I am not sure if both the declarations are equivalent. What makes (2) different from (1)? ...

How can I make an optional argument in my custom function in PHP?

For example, here's a quick dummy function that sums it up: function dummy_func($optional) { if (!isset($optional) { $optional = "World!"; } $output = "Hello " . $optional; return $output; } However, if I run this, I get an E_WARNING for a missing argument. How can I set it up so it doesn't flag an error? ...

Scoping problem when sfApply is used within function (package snowfall - R)

Let me add another scoping problem in R, this time with the snowfall package. If I define a function in my global environment, and I try to use that one later in an sfApply() inside another function, my first function isn't found any more : #Runnable code. Don't forget to stop the cluster with sfStop() require(snowfall) sfInit(parallel=...

php calculations and echoing?

i have this function that takes two values and displays them, but its not doing the calculation right? php code: formatVote($votes_up,$votes_down) $net_vote = $votes_up - $votes_down; return <<<ENDOFRETURN <strong>$net_vote</strong> ENDOFRETURN; html page: <?php //rows retrieved from database.... formatVote($row['votes_up'],$...

PHP Function 'return' not returning

This is a bit of an oddity for me. PHP is my forte, and I can normally figure out any issue I encounter. I have a custom framework that I have been using for years. I have taken it upon myself to rewrite it, and I'm doing everything essentially the same that I was before. The problem lies in the following construct: function ModPages_G...

In Lisp, how do I fix "Warning: Assumed Special?"

In this file I get 9 warnings of "assumed special". They are ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special in SETQ ;;;*** Warning in CHECK-ROW: RESULT assumed special in SETQ ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special ;;;*** Warning in CHECK-ROW: CHECKARRAY a...

Setting default function parameters with variable in php

I would like to do something like: function func($var1 = 'Hello', $var2 = "{$var1} World") { echo $var2; } This is not possible! My idea is to avoid extra code lines inside my function but I don't know if that is possible. Does someone know if a similar procedure is possible in php? Thanks. ...

Using "Static" Keyword to Limit Access in C++ Member Functions

I understand that one benefit of having static member functions is not having to initialize a class to use them. It seems to me that another advantage of them might be not having direct access to the class's not-static stuff. For example a common practice is if you know that a function will have arguments that are not to be changed, to...

In functionally programmed javascript, is there any penalty to returning a callback rather than just calling a callback?

I do this out of habit: function process( fn ){ // Some process that builds data return fn( data ); } It is not always necessary to return the callback, and I would like to know if there is any performance hit in doing that over simply calling the callback: function process( fn ){ // Some process that builds data fn( dat...

How to include the general file name, taken as function argument in Matlab, in the path location?

BRIEF SUMMARY OF WHAT I WANT: If I take a file name as argument of a function, how do I include that file name in the path location such that the name of the file in the path location is the one user enters. If you didn't understand what I am saying, then read below for explanation: SECONDARY EXPLANATION: I am making a general functio...