functional-programming

LISP - destructive and non-destructive constructs

谁都会走 提交于 2019-12-22 04:45:20
问题 What is the correct definition of destructive and non-destructive constructs in LISP (or in general). I have tried to search for the actual meaning but I have only found a lot of usage of these terms without actually explaining them. It came to my understanding, that by destructive function is meant a function, that changes the meaning of the construct (or variable) - so when I pass a list as a parameter to a function, which changes it, it is called a destructive operation, because it changes

Has anyone proposed a Pipe operator for javascript?

北慕城南 提交于 2019-12-22 04:43:16
问题 Many languages have an operator that allows you to pipe the results of one operation into a call to another (e.g. the | operator in bash, the |> operator in F#). One of the great advantages to my mind of the common idiom of method chaining in javascript is that it reads top-to-bottom, left-to-right: var fooOddSquares = [1, 2, 3, 4, 5] .filter(x => x % 2) .map(x => "foo" + x * x) .reduce(((acc, str, i) => acc[i + 1] = str; return acc), {}); // => {1: "foo1", 2: "foo9", 3: "foo25"} compared to

Is there something like the threading macro from Clojure in Python?

╄→гoц情女王★ 提交于 2019-12-22 04:34:07
问题 In Clojure I can do something like this: (-> path clojure.java.io/resource slurp read-string) instead of doing this: (read-string (slurp (clojure.java.io/resource path))) This is called threading in Clojure terminology and helps getting rid of a lot of parentheses. In Python if I try to use functional constructs like map , any , or filter I have to nest them to each other. Is there a construct in Python with which I can do something similar to threading (or piping) in Clojure? I'm not looking

Using elm higher order functions for keyboard events

♀尐吖头ヾ 提交于 2019-12-22 04:31:18
问题 I am trying to create a higher order function to create functions to capture only a specific key code. The code is inspired on Evan's "onEnter" function from his todomvc implementation which captures only the enter function. onKeyCode : Int -> Msg -> Attribute Msg onKeyCode keycode msg = let captureKey code = if code == keycode then msg else NoOp in on "keydown" (Json.map captureKey keyCode) onEnter = onKeyCode 13 onEsc = onKeyCode 27 And now I want to add that to an input component in the

Using elm higher order functions for keyboard events

无人久伴 提交于 2019-12-22 04:31:16
问题 I am trying to create a higher order function to create functions to capture only a specific key code. The code is inspired on Evan's "onEnter" function from his todomvc implementation which captures only the enter function. onKeyCode : Int -> Msg -> Attribute Msg onKeyCode keycode msg = let captureKey code = if code == keycode then msg else NoOp in on "keydown" (Json.map captureKey keyCode) onEnter = onKeyCode 13 onEsc = onKeyCode 27 And now I want to add that to an input component in the

Recursive anonymous functions in SML

孤街浪徒 提交于 2019-12-22 04:29:11
问题 Is it possible to write recursive anonymous functions in SML? I know I could just use the fun syntax, but I'm curious. I have written, as an example of what I want: val fact = fn n => case n of 0 => 1 | x => x * fact (n - 1) 回答1: The anonymous function aren't really anonymous anymore when you bind it to a variable. And since val rec is just the derived form of fun with no difference other than appearance, you could just as well have written it using the fun syntax. Also you can do pattern

Immutable game object, basic functional programming question

不羁的心 提交于 2019-12-22 04:25:06
问题 I'm in the process of trying to 'learn more of' and 'learn lessons from' functional programming and the idea of immutability being good for concurrency, etc. As a thought exercise I imagined a simple game where Mario-esq type character can run and jump around with enemies that shoot at him... Then I tried to imagine this being written functionally using immutable objects. This raised some questions that puzzled me (being an Imperative OO programmer). 1) If my little guy at position x10,y100

infinite loop in functional programming?

和自甴很熟 提交于 2019-12-22 04:21:33
问题 I was wondering: can infinite loops be done in functional programming? example: when using the windows API to get windows messages, it is usually implemented in a loop. I know it is possible to make a function that will keep going into recursion indefinitely. I expect that this will result in a stack overflow. are infinite loop the wrong mind-set for functional programming ? is the interface of the operating system or the hardware the problem ? it doesn't seem to me like a functional program

infinite loop in functional programming?

£可爱£侵袭症+ 提交于 2019-12-22 04:21:05
问题 I was wondering: can infinite loops be done in functional programming? example: when using the windows API to get windows messages, it is usually implemented in a loop. I know it is possible to make a function that will keep going into recursion indefinitely. I expect that this will result in a stack overflow. are infinite loop the wrong mind-set for functional programming ? is the interface of the operating system or the hardware the problem ? it doesn't seem to me like a functional program

Analysis and Design for Functional Programming [closed]

房东的猫 提交于 2019-12-22 04:14:23
问题 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 . How do you deal with analysis and design phases when you plan to develop a system using a functional programming language like Haskell