functional-programming

What is the most minimal functional programming language?

你说的曾经没有我的故事 提交于 2019-12-20 08:56:08
问题 What is the most minimal functional programming language? 回答1: It depends on what you mean by minimal. To start with, the ancestor of functional languages is, first and foremost, mathematical logic . The computational use of certain logics came after the fact. In a sense, many mathematical systems (the cores of which are usually quite minimal) could be called functional languages. But I doubt that's what you're after! Best known is Alonzo Church's lambda calculus, of which there are variants

Clojure: How to find out the arity of function at runtime?

孤者浪人 提交于 2019-12-20 08:56:07
问题 Given a function object or name, how can I determine its arity? Something like (arity func-name) . I hope there is a way, since arity is pretty central in Clojure 回答1: The arity of a function is stored in the metadata of the var. (:arglists (meta #'str)) ;([] [x] [x & ys]) This requires that the function was either defined using defn , or the :arglists metadata supplied explicitly. 回答2: Sneaky reflection: (defn arg-count [f] (let [m (first (.getDeclaredMethods (class f))) p (

How to replace for-loops with a functional statement in C#?

一世执手 提交于 2019-12-20 08:48:23
问题 A colleague once said that God is killing a kitten every time I write a for-loop. When asked how to avoid for-loops, his answer was to use a functional language. However, if you are stuck with a non-functional language, say C#, what techniques are there to avoid for-loops or to get rid of them by refactoring? With lambda expressions and LINQ perhaps? If so, how? Questions So the question boils down to: Why are for-loops bad? Or, in what context are for-loops to avoid and why? Can you provide

Should functional programming be taught before imperative programming? [closed]

时光毁灭记忆、已成空白 提交于 2019-12-20 08:47:07
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . It seems to me that functional programming is a great thing. It eliminates state and makes it much easier to automatically make code

How does functional programming apply to simulations?

↘锁芯ラ 提交于 2019-12-20 08:46:18
问题 Besides the general question in the title, How do functional programmers and functional languages approach the domain of simulations, which seem to be most naturally handled by object-oriented languages? Are there open-source examples of complex simulations written in a (mostly) functional style? What changes of perspective would an OO-programmer need, in order to approach simulations from a functional paradigm? I'm asking this while learning how Clojure's creator Rich Hickey specifically

Functional Reactive F# - Storing States in Games

蓝咒 提交于 2019-12-20 08:41:29
问题 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 of the ball (or state). So I always pass the current position of the ball as the parameter of the global function. If we talk about slight more complex games,

Using Reader Monad for Dependency Injection

杀马特。学长 韩版系。学妹 提交于 2019-12-20 08:40:45
问题 I recently saw the talks Dead-Simple Dependency Injection and Dependency Injection Without the Gymnastics about DI with Monads and was impressed. I tried to apply it on a simple problem, but failed as soon as it got non-trivial. I really would like to see a running version of dependency injection where a class that depends on more than one value that has to be injected a class that depends on a class that depends on something to be injected as in the following example trait FlyBehaviour { def

Are there any tools for performing static analysis of Scala code? [closed]

谁说胖子不能爱 提交于 2019-12-20 08:27:45
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Are there any tools for performing static analysis of Scala code, similar to FindBugs and PMD for Java or Splint for C/C++? I know that FindBugs works on the bytecode produced by compiling Java, so I'm curious as to how it would work on Scala. Google searches (as of 27 October 2009) reveal very little. Google

recursive descent parser and functional programming

青春壹個敷衍的年華 提交于 2019-12-20 08:26:23
问题 So lately I have been working on writing a simple compiler to better understand compiler concepts. Being a diligent reader of stackoverfolow, it seems there is a consensus that writing a compiler in a functional language is easier than an imperative one. To this end I thought I would try and kill two birds and write a compiler in F# to both learn a functional language and write a compiler at the same time. I have been reading through the dragon book and decided to start with a recursive

Is Ruby a functional language?

笑着哭i 提交于 2019-12-20 08:13:37
问题 Wikipedia says Ruby is a functional language, but I'm not convinced. Why or why not? 回答1: I most definitely think you can use functional style in Ruby. One of the most critical aspects to be able to program in a functional style is if the language supports higher order functions... which Ruby does. That said, it's easy to program in Ruby in a non-functional style as well. Another key aspect of functional style is to not have state, and have real mathematical functions that always return the