So I was having a debate with a fellow engineer about looping in JavaScript. The issue was about the native for loop construct and prototype's each() method. Now I know there are lots of docs/blogs about for and for-each, but this debate is somewhat different and I would like to hear what some of you think.
Let's take the following loop...
I recently getting to know about functional programming (in Haskell and Scala). It's capabilities and elegance is quite charming.
But when I met Monads, which makes use of an algebraic structure named Monoid, I was surprised and glad to see the theoretic knowledge I have been learning from Mathematics is made use of in programming.
T...
Hi!
In a project of mine one common use case keeps coming up. At some point I've got a sorted collection of some kind (List, Seq, etc... doesn't matter) and one element of this collection. What I want to do is to swap the given element with it's following element (if this element exists) or at some times with the preceding element.
I'm...
Hey, I know this is an subjective question, but please don't vote to close it before I get the acceptable answer.
I'm a .NET programmer (somewhat experienced), and really want to learn a functional language. My preferred choices are F# and Python, and I'm really doubting about which one to choose. Please clear my doubts. I'm totally new...
I am a student currently learning about Functional Reactive paradigm using F#. It's radically new viewpoint for me. Yesterday I learned about creating a simple ping-pong game using this paradigm. The idea I grasp so far is : we think values as functions of time. On its pure form, it's stateless. However, I need to remember the position o...
I'm serializing data which may be an integer, an object (list) with other nested objects, and trying to make a choice as to what approach to be using. Of two, the first one is to create bytevectors recursively and copy them in the calling functions to a larger single bytevector; the second one is to use some kind of the stream I could wr...
Hello, I have a job model which has many attributes. I would like to use graphics to display the sum of some of these attributes. For that, I am using the following code in the javascript portion of the view which produces the graph:
<% for job in @daily_jobs %>
['<%= job.day %>',<%= job.walltime %>],
<% end %>
This returns ...
What are the pros and cons of closures against classes, and viceversa?
Edit:
As user Faisal put it, both closures and classes can be used to "describe an entity that maintains and manipulates state", so closures provide a way to program in an object oriented way using functional languages. Like most programmers, I'm more familiar with ...
Hi all,
I'm a C# guy looking to learn F# and functional programming.
I'm hearing a lot about "monads" .. which I think (thanks to Google), are called "Computation Expressions" in F#?
One aspect I'm trying to bend my head round is the State Monad/Computation Expression... But I need an idiot-proof, line-by-line, explanation about what'...
Hello, I would like to know if there are some tools and techniques for diagramming in functional languages like Lisp, Clojure, etc.
Something like UML in OOP languages, perhaps?
...
EDIT: tr/// does not support variable interpolation, so I went with s/\Q$_\E//g; instead
Or, more likely, I'm not doing something right...
I have the following code:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
sub strip_invalid {
my ($str, @chars) = @_;
map { $str =~ tr/$_//; } @chars;
return $str;
}
my @invalid = q...
I am interested in (functional) vector manipulation in R. Specifically, what are R's equivalents to Perl's map and grep?
The following Perl script greps the even array elements and multiplies them by 2:
@a1=(1..8);
@a2 = map {$_ * 2} grep {$_ % 2 == 0} @a1;
print join(" ", @a2)
# 4 8 12 16
How can I do that in R? I got this far, us...
I was introduced to Clojure not long ago, and while I haven't fully assimilated all of it's concepts, It has given me an alternative to Java and PHP's OO that I really want to move towards. I consider Clojure's systems to be my ideal. I know that I want to let it inform my PHP coding style as much as I can.
I really don't like OO in P...
I'd like to show the observation number for each record returned by a PostgreSQL query.
I think in 8.4 windowing functions can perform this capability.
Edit:
I think I just found the answer, but since this hasn't been asked before, I'll keep the question open. I also welcome non-windowing function possibilities.
Edit 2:
So a little t...
Has an emulation of J style of super condensed tacit programming via verbs, adverbs, forks, etc., ever been attempted via libraries for mainstream functional languages?
If so, how successful was the result?
If not, is there a technical issue that makes this impossible, or is it just not worth doing?
I'm particularly interested in cons...
Suppose I have a single element, and I have a list of predicates (functions). I want to apply each of these predicates to the single element and get a corresponding list of return values. I know that map and friends can apply a single function to each a list of arguments, but is there any concise syntax to apply many functions to a singl...
Hi all,
I have a list in scala called l : List[AType] that I want to change to list[String].
This may sound like a very dirty, inefficient approach, but I'm not quite sure of the best way to do this. My code was:
var result = new Array[String]("a","b")
l foreach { case a => result = result :+ (a.toString().toUpperCase()); }
result toL...
Given a LL(1) grammar what is an appropriate data structure or algorithm for producing an immutable concrete syntax tree in a functionally pure manner? Please feel free to write example code in whatever language you prefer.
My Idea
symbol : either a token or a node
result : success or failure
token : a lexical token from source text...
In college I took on a class on modern physics, in which we learned about special relativity. I was completely blown away by how different frames of reference could actually observe physical properties of an object to be different and neither be incorrect. Over time, this concept has slowly been changing the way I program, to the point...
My anonymous func test below is executed only once:
repeat i 5 [
func[test][
print test
] rejoin ["test" i]
]
I am obliged to name it to be able to execute it 5 times as expected:
repeat i 5 [
test: func[test][
print test
] test rejoin ["test" i]
]
This is weird. isn't it really possible to use anonymous function in...