imperative

Sieve of Eratosthenes Scheme

岁酱吖の 提交于 2019-12-29 08:05:42
问题 I've been searching the web for an implementation of the Sieve of Eratosthenes in scheme and although I came up with a lot of content, none of them seemed to have made it like I need it to be done. The problem is most algorithms either use a static end or use iteration. This paired with my lack of knowledge of the language led me to ask all of you for help. I need an implementation of the Sieve that takes in one argument (number to Sieve until), uses only recursion and has a list of "cons" of

Are the implementation details of declarative languages inherently imperative

╄→гoц情女王★ 提交于 2019-12-06 03:47:06
问题 I'm reading 'Functional Programming' by Tomas Petricek & Jon Skeet and I understand the difference between declarative & imperative programming. What I was wondering is how are the primitive operators & functions implemented, are declarative languages constructed from imperative operators & functions. Cheers AWC 回答1: If I understand your question correctly, I don't think that is a hard and fast rule. For example, you can use a functional language like Lisp, to create an interpreter for itself

Are the implementation details of declarative languages inherently imperative

大兔子大兔子 提交于 2019-12-04 07:26:01
I'm reading 'Functional Programming' by Tomas Petricek & Jon Skeet and I understand the difference between declarative & imperative programming. What I was wondering is how are the primitive operators & functions implemented, are declarative languages constructed from imperative operators & functions. Cheers AWC If I understand your question correctly, I don't think that is a hard and fast rule. For example, you can use a functional language like Lisp, to create an interpreter for itself. In this case, the implementation details are implemented in a functional manner (because Lisp is a

How do I code a tree of objects in Haskell with pointers to parent and children?

不打扰是莪最后的温柔 提交于 2019-12-03 12:57:39
问题 I've got the following problem: I have a tree of objects of different classes where an action in the child class invalidates the parent. In imperative languages, it is trivial to do. For example, in Java: public class A { private List<B> m_children = new LinkedList<B>(); private boolean m_valid = true; public void invalidate() { m_valid = false; } public void addChild(B child) { m_children.add(child); child.m_parent = this; } } public class B { public A m_parent = null; private int m_data = 0

How do I code a tree of objects in Haskell with pointers to parent and children?

安稳与你 提交于 2019-12-03 03:08:14
I've got the following problem: I have a tree of objects of different classes where an action in the child class invalidates the parent. In imperative languages, it is trivial to do. For example, in Java: public class A { private List<B> m_children = new LinkedList<B>(); private boolean m_valid = true; public void invalidate() { m_valid = false; } public void addChild(B child) { m_children.add(child); child.m_parent = this; } } public class B { public A m_parent = null; private int m_data = 0; public void setData(int data) { m_data = 0; m_parent.invalidate(); } } public class Main { public

Scala Performance: imperative vs functional style

北慕城南 提交于 2019-12-01 00:01:30
问题 I'm new to Scala and was just reading Scala By Example. In chapter 2, the author has 2 different versions of Quicksort. One is imperative style: def sort(xs: Array[Int]) { def swap(i: Int, j: Int) { val t = xs(i); xs(i) = xs(j); xs(j) = t } def sort1(l: Int, r: Int) { val pivot = xs((l + r) / 2) var i = l; var j = r while (i <= j) { while (xs(i) < pivot) i += 1 while (xs(j) > pivot) j -= 1 if (i <= j) { swap(i, j) i += 1 j -= 1 } } if (l < j) sort1(l, j) if (j < r) sort1(i, r) } sort1(0, xs

Sieve of Eratosthenes Scheme

一个人想着一个人 提交于 2019-11-29 11:45:16
I've been searching the web for an implementation of the Sieve of Eratosthenes in scheme and although I came up with a lot of content, none of them seemed to have made it like I need it to be done. The problem is most algorithms either use a static end or use iteration. This paired with my lack of knowledge of the language led me to ask all of you for help. I need an implementation of the Sieve that takes in one argument (number to Sieve until), uses only recursion and has a list of "cons" of a number with a #t (true) or #f (false). So essentially the algorithm would go as such: Make list from

closures and objects [closed]

橙三吉。 提交于 2019-11-28 20:49:12
Functional programming .. is like classic ( Mark Twain's type ). While reading another articles about SICP, where people are talking about the great impact closures had on there thinking, i got reminded of this, which i read ages ago Closures are poor man's objects Objects are poor man's closure ( Can't recall exact source but it was programmers rosetta stone, or zen of programming, or tau of programming ... google has become so crowded that can't go to original source ) So co-programmers ... What is your take ... are closure something that you were always missing .. or just some syntactic

closures and objects [closed]

房东的猫 提交于 2019-11-27 13:12:48
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . Functional programming .. is like classic ( Mark Twain's type). While reading another articles about SICP, where people are talking about the great impact closures had on there thinking, i got reminded of this, which i read ages ago Closures are poor man's objects Objects are