How have you used the meta data information in your Clojure Program?
I saw one example from Programming Clojure
(defn shout [#^{:tag String} message] (.toUpperCase message))
;; Clojure casts message to String and then calls the method.
What are some of the usage? This form of programming is completely new to me. Thanks.
...
Why do people prefer list comprehensions like
(for [x '(1 2 3)] (* 2 x)) instead of (map #(* %1 2) '(1 2 3))?
Are there benefits to this kind of programming?
1. Is it more readable?
2. Is it faster in some cases?
3. Is it better for certain kinds of operations and data structures?
...
I am learning functional programming concepts now a days, and professionally I am an Asp.net developer. But asp.net makes you to change properties of objects too often in code behind. Functional programming is based on immutable objects. And apply this concept to change the value of a textbox will be very painful. Also in some event hand...
I just wondered whether it's possible to match against the same values for multiple times with the pattern matching facilities of functional programming languages (Haskell/F#/Caml).
Just think of the following example:
plus a a = 2 * a
plus a b = a + b
The first variant would be called when the function is invoked with two similar va...
(defmacro nif [expr pos zer neg]
'(condp = (Integer/signum ~expr)
-1 ~neg
0 ~zer
1 ~pos))
I get this error.
1:1 user=> #<Namespace Chapter7Macros>
1:2 Chapter7Macros=> (nif 1 (+ 2 2) (- 2 2) (- 3 2))
1:3 Chapter7Macros=> java.lang.Exception: Unable to resolve symbol: expr in this context (repl-1:57)
...
Somebody please explain the usage of reduction semantics and the PLT Redex in simpler language.
Thanks.
...
Could someone propose better and/or more elegant implementation of this:
let each xs =
let rec each' acc left right =
match right with
| [] -> acc
| right -> let new_left = left @ [List.hd right]
let next = List.tl right
let result = (List.hd right), left @ next
...
First of all, the goofy title is directly referencing this paper:
http://eprints.eemcs.utwente.nl/7281/01/db-utwente-40501F46.pdf
I understand the theoretical value of this, as it models most, if not all, programming semantics.
What problems are most efficiently and practically solved with a programming paradigm based on this? What pr...
Hello, I'm having trouble with classes in haskell.
Basically, I have an algorithm (a weird sort of graph-traversal algorithm) that takes as input, among other things, a container to store the already-seen nodes (I'm keen on avoiding monads, so let's move on. :)). The thing is, the function takes the container as a parameter, and calls j...
Is it possible to write an impure template in C++? That is, a template that will sometimes give a different resulting type or int for the same template parameters. For example, is it possible to write a template Foo<T> where Foo<int>::type is sometimes char and at other times float? Or a template Foo<T> where Foo<double>::my_static_const...
I'm quite new to that functional programming paradigm, but so far I like it. Since I'm into game development, I want to try it out in writing some games in purely functional programming style. I don't mind the language - be it Erlang, Haskell, Lisp, or even Ruby (I found out it supports functional programming traits).
Well, it is obviou...
EDIT: Highlight difficulties with virtual and/or value-type methods
Can you create a delegate of an instance method without specifying the instance at creation time? In other words, can you create a "static" delegate that takes as it's first parameter the instance the method should be called on?
For example, how can I construct the fo...
One more question about most elegant and simple implementation of element combinations in F#.
It should return all combinations of input elements (either List or Sequence).
First argument is number of elements in a combination.
For example:
comb 2 [1;2;2;3];;
[[1;2]; [1;2]; [1;3]; [2;2]; [2;3]; [2;3]]
...
Hi,
I have to write a program to solve quadratics, returning a complex number result.
I've gotten so far, with defining a complex number, declaring it to be part of num, so +,- and * - ing can take place.
I've also defined a data type for a quadratic equation, but im now stuck with the actual solving of the quadratic. My math is quite...
I am considering ditching Ruby on Rails for my web-development pet-project and using a functional programming language (with or without a framework).
Not that there is anything wrong with RoR, but I'd just like to learn something else and it seems a good way to learn functional programming.
I know of a couple frameworks (Lift for Scala a...
I am interested in finding if producer-consumer problem when there are multiple produce and multiple consumer be solved without using assignment i.e., using functional style of programming? How?
Producer-consumer problem
Thanks
...
So, I have a function of type:
genTree :: Node -> [Nodes]
Given a node, this function generates the set of children of that node in a tree. The function can be applied again to those children to generate their children, until it eventually generates a node with no children, i.e. a node for which genTree returns [].
What I'm trying t...
I have looking to Haskell questions in SO, and I recovering my university notes on funtional programming as a hobby. But I've always wondered how could something done in Haskell get outside Hugs interpreter and integrate with a C#, C++ or Java project. Has anybody done that? How?
...
What I'm looking for is this function:
def maybe[A, B](a: Option[A])(f: A => B)(g: () => B): B = a match
{
case Some(x) => f(x)
case None => g()
}
It's in the Haskell prelude so I'm thinking it might be in the Scala standard library somewhere and I've just missed it. I hate having to recode it in projects so I'm wondering if ...
I was reading Shriram's PLAI and this I got stuck in these questions:
Can you prove that the eager and lazy regimes will always produce the same answer? (Shriram asks to look at the language he developed but is there another way to prove this and how?)
Will eager evaluation always reduce with fewer steps?
Here is the Code of Substitu...