I have a function inside a loop inside a function. The inner function acquires and stores a large vector of data in memory (as a global variable... I'm using "R" which is like "S-Plus"). The loop loops through a long list of data to be acquired. The outer function starts the process and passes in the list of datasets to be acquired.
I p...
I'm learning functional programming, and have tried to solve a couple problems in a functional style. One thing I experienced, while dividing up my problem into functions, was it seemed I had two options: use several disparate functions with similar parameter lists, or using nested functions which, as closures, can simply refer to bindin...
I've just finished a six hour debugging session for a weird UI effect where I found that my favorite framework's implementation of an interface function called "getVisibleRegion" disabled some UI feature (and apparently forgot to restore it).
I've filed a bug with the framework, but this made me think about proper design: under what co...
I've seen methods like this:
public void Foo(List<string> list)
{
list.Add("Bar");
}
Is this good practice to modify parameters in a method?
Wouldn't this be better?
public List<string> Foo(List<string> list)
{
// Edit
List<string> newlist = new List<string>(list);
newlist.Add("Bar");
return newlist;
}
It just ...
I'm working on a project on an 8051 where every byte counts. As such, I am using some global variables where I normally wouldn't. The normal method of passing pointers into a function adds too much overhead here.
I have a number of functions that use single bit variables (a compiler specific extension to C) to signal the outcome of a ...
I feel the term rather pejorative. Hence, I am flabbergasted by the two sentences in Wikipedia:
Imperative programming is known for
employing side effects to make
programs function. Functional
programming in turn is known for its
minimization of side effects. [1]
Since I am somewhat Math-biased, the latter sounds excellen...
So I'm currently working on a new programming language. Inspired by ideas from concurrent programming and Haskell, one of the primary goals of the language is management of side effects. More or less, each module will be required to specify which side effects it allows. So, if I were making a game, the graphics module would have no abili...
As I always understood it, any change to the programs state (or anything to do with IO) is a side effect. It does not matter, whether the change occurs in a global variable or in a private field of the object the method is called on. It follows that all methods which do not return anything either do nothing at all or have a side effect. ...
I've got an idea for caching that I'm beginning to implement:
Memoizing functions and storing the return along with a hash of the function signature in Velocity. Using PostSharp, I want to check the cache and return a rehydrated representation of the return value instead of calling the function again. I want to use attributes to control...
At the moment I'm aware of the following methods to integrate side-effects into purely functional programming languages:
effect systems
continuations
unique types
monads
Monads are often cited to be the most effective and most general way to do this.
Which other methods exist? How do they compare?
...
I have an NSArray of Foos in an Objective-C program. I would like to call the doIt function of each Foo, however, the makeObjectsPerformSelector function of NSArray does not allow the original Foos to be modified, per the docs. The doIt selector changes the m data member for each Foo when doIt is called. How do I go about efficiently per...
I have a method that is producing side effects, even though certain variables are marked final. Why is this? Perhaps I am confused about what final does.
@Test
public void testSubGraph() {
WeightedGraph<String, DefaultWeightedEdge> g = generateSimpleCaseGraph();
Graph<String, DefaultWeightedEdge> sub = ChooseRoot.subgraphInDirection(...
Hi, I'm using the code below to free up memory on some running programs because my own program needs large memory resources to run faster.
[DllImport("psapi.dll")]
public static extern bool EmptyWorkingSet(IntPtr hProcess);
public FreeMem(string programName){
EmptyWorkingSet(Process.GetCurrentProcess().Handle);
foreach(Pro...
I have been trying to wrap my head around functional programming for a while now? I have looked up lambda calculus, LISP, OCML, F# and even combinatorial logic but the main problem I have is how do you do things that require side effects like (interacting with a user, communicating with a remote service, or even handle simulating using ...
I understand the Decorator pattern, in it's simplest terms. The idea being that one class wraps another, where a decorator method wishes to run some other code before and/or after calling the same method on the decorated object.
However, I have run into the situation where I cannot simply call the decorated method, as it has some undes...
monads are described as the haskell solution to deal with IO. I was wondering if there were other ways to deal with IO in pure functional language.
...
I am considering moving from Matlab to Python/numpy for data analysis and numerical simulations. I have used Matlab (and SML-NJ) for years, and am very comfortable in the functional environment without side effects (barring I/O), but am a little reluctant about the side effects in Python. Can people share their favorite gotchas regarding...
#include<stdio.h>
#include<conio.h>
#define ABC 20
#define XYZ 10
#define XXX ABC - XYZ
void main()
{
int a;
a = XXX * 10;
printf("\n %d \n", a);
getch();
}
I thought the output should be 100 but when i saw the result i found o/p as -80. when i put bracket as #define XXX (ABC-XYZ) then i get output as 100 but wi...
In the context of functional programming, a typical example of a side effect is "launch the missiles". I was just wondering where that expression comes from historically.
...
I'm not sure exactly how much this falls under 'programming' opposed to 'program language design'. But the issue is this:
Say, for sake of simplicity we have two 'special' lists/arrays/vectors/whatever we just call 'ports' for simplicity, one called stdIn and another stdOut. These conceptually represent respectively
All the user input...