higher-order-functions

Attempting to trick NetLogo into executing a function passed as an argument

会有一股神秘感。 提交于 2021-02-10 14:50:21
问题 The following produces a compilation error. to-report call-first/last [first/last a-list] report first/last a-list end a-list in the body is highlighted with the error: Expected command. So I tried the following. to-report call-first/last [first/last a-list] report first map first/last (list a-list) end This code compiled(!), but when I attempted to have the observer execute it call-first/last first [1 2 3] call-first/last was highlighted with the error message: CALL-FIRST/LAST expected 2

Convert List comprehension into recursive call

落爺英雄遲暮 提交于 2021-02-10 12:10:40
问题 sieve [] = [] sieve (a:x) = a : sieve [y| y <- x, y `mod` a > 0] I want to convert this code to recursive implementation or using higher order functions such as map and filter. I can't figure out how do I do this. I have tried this way but it wont seem to work sieve (a:x) = f x : map f xs where f = y `mod` a > 0 回答1: Is this the kind of thing you want? The list comprehension is only being used to filter the list anyway, so we can convert to a form that manually applies a filter. sieve [] = []

Convert List comprehension into recursive call

本秂侑毒 提交于 2021-02-10 12:04:41
问题 sieve [] = [] sieve (a:x) = a : sieve [y| y <- x, y `mod` a > 0] I want to convert this code to recursive implementation or using higher order functions such as map and filter. I can't figure out how do I do this. I have tried this way but it wont seem to work sieve (a:x) = f x : map f xs where f = y `mod` a > 0 回答1: Is this the kind of thing you want? The list comprehension is only being used to filter the list anyway, so we can convert to a form that manually applies a filter. sieve [] = []

how do I apply a function n times? [closed]

a 夏天 提交于 2021-02-07 18:27:26
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . Improve this question I have been trying without much success to implement a higher order function that would take in repeat(f, n) where f is another function and n is the integer value that says how many times n will be applied to a variable x. For example: def integer(x): x + 1 so i would have

Is there a higher order Prolog that wouldn't need a type system?

大兔子大兔子 提交于 2021-01-27 10:08:39
问题 I suspect that λProlog needs a type system to make their higher order unification sound. Otherwise through self application some Russell type anomalies can appear. Are there alternative higher order Prologs that don't need .sig files? Maybe by a much simpler type system, that doesn't need that many declarations but still has some form of higher order unification? Can this dilemma be solved? 回答1: Is there a higher order Prolog that wouldn't need a type system? These are type-free: HiLog HiOrd

Is there a higher order Prolog that wouldn't need a type system?

為{幸葍}努か 提交于 2021-01-27 10:07:27
问题 I suspect that λProlog needs a type system to make their higher order unification sound. Otherwise through self application some Russell type anomalies can appear. Are there alternative higher order Prologs that don't need .sig files? Maybe by a much simpler type system, that doesn't need that many declarations but still has some form of higher order unification? Can this dilemma be solved? 回答1: Is there a higher order Prolog that wouldn't need a type system? These are type-free: HiLog HiOrd

Turning Map(“a” -> 2, “b” -> 1) into seq(“a”,“a”,“b”) using map

拟墨画扇 提交于 2021-01-20 09:43:01
问题 I am trying to turn a Map("a" -> 2, "b" -> 1) into seq("a","a","b") through the map function, Currently I am trying to run the code below giving me the desired result. Is there a smarter way to do this? Possibly a better way through the map function? var multiset : Seq[T] = Seq[T]() var variables : Seq[T] = data.map(x => x._1).toSeq var variableCounts : Seq[Int] = data.map(x => x._2).toSeq for(x <- 0 until variables.length){ for(y <- 0 until variableCounts(x)) multiset = multiset :+ variables

Turning Map(“a” -> 2, “b” -> 1) into seq(“a”,“a”,“b”) using map

这一生的挚爱 提交于 2021-01-20 09:42:11
问题 I am trying to turn a Map("a" -> 2, "b" -> 1) into seq("a","a","b") through the map function, Currently I am trying to run the code below giving me the desired result. Is there a smarter way to do this? Possibly a better way through the map function? var multiset : Seq[T] = Seq[T]() var variables : Seq[T] = data.map(x => x._1).toSeq var variableCounts : Seq[Int] = data.map(x => x._2).toSeq for(x <- 0 until variables.length){ for(y <- 0 until variableCounts(x)) multiset = multiset :+ variables

Turning Map(“a” -> 2, “b” -> 1) into seq(“a”,“a”,“b”) using map

人走茶凉 提交于 2021-01-20 09:41:10
问题 I am trying to turn a Map("a" -> 2, "b" -> 1) into seq("a","a","b") through the map function, Currently I am trying to run the code below giving me the desired result. Is there a smarter way to do this? Possibly a better way through the map function? var multiset : Seq[T] = Seq[T]() var variables : Seq[T] = data.map(x => x._1).toSeq var variableCounts : Seq[Int] = data.map(x => x._2).toSeq for(x <- 0 until variables.length){ for(y <- 0 until variableCounts(x)) multiset = multiset :+ variables

How to view higher-order functions and IO-actions from a mathematical perspective?

左心房为你撑大大i 提交于 2020-12-26 04:03:51
问题 I am trying to understand functional programming from first principles, yet I am stuck on the interface between the pure functional world and the impure real world that has state and side effects. From a mathematical perspective, what is a function that returns a function? what is a function that returns an IO action (like Haskell's IO type)? To elaborate: In my understanding, a pure function is a map from domain to co-domain. Ultimately, it is a map from some values in computer memory to