Hot answers tagged

55

It's called banker's rounding. The idea is to minimize the cumulative error from many rounding operations. Lets say you always rounded .5 down. Think of all those little interest payments, the bank pocketing half a cent each time... Lets say you always rounded .5 up. Accounting is going to scream because you're paying out more interest than you should.


43

Is LISP still practiced/used in todays world, or is it a legacy language Yes, it is, but you have to know where to look. People who use LISP don't tend to shout too loudly about it but there's a handful of examples of a few high-profile startups having used it to great effect over the last 20 years. It is also very popular with small companies in Europe. ...


40

A while ago I constructed a test program for successive rounding, because it's basically a worst-case stress test for a rounding algorithm. For each number from 0 to 9,999 it first rounds to the nearest 10, then to the nearest 100, then to the nearest 1000. (You could also think of this as 10,000 points in [0,1) being rounded to 3 places, then to 2, then to ...


29

Many Lispers will tell you that what makes Lisp special is homoiconicity, which means that the code's syntax is represented using the same data structures as other data. For example, here's a simple function (using Scheme syntax) for calculating the hypotenuse of a right-angled triangle with the given side lengths: (define (hypot x y) (sqrt (+ (square x) (...


23

A dissenting opinion: Lisp's homoiconicity is far less of a useful thing than most Lisp fans would have you believe. To understand syntactic macros, it's important to understand compilers. The job of a compiler is to turn human-readable code into executable code. From a very high-level perspective, this has two overall phases: parsing and code generation....


18

Short Answer: There is a simple solution to your problem. Just install the virtual-machine with Linux (Ubuntu) - it is free. I am also a mainly .NET developer who loves to experiment different things, or try variety of frameworks and/or development tools. The main thing here is not to mess your main development environment. Thus, installing everything in a ...


17

Queues don't functionally compose, and are difficult to implement in a well-performing way without making them mutable. The very nature of a queue suggests that you put things into it and take things out of it, which is at odds with the immutable nature of functional languages. Oh, sure, you can do the same thing with lists, but generally what you are ...


14

Denotational design (program design rooted in and flowing from denotational semantics) is my primary methodology. A few years ago while writing about FRP, I got much clearer about what I'd been doing. See Push-pull functional reactive programming. For a more explicit description of the paradigm and a variety of examples, see Denotational design with type ...


14

In my first year at the university the first programming course I took was using SICP (that was 1988). However, I had a similar problem like you: for my own computer (actually a Commodore Amiga), there was no Scheme implementation available at that time, only a different Lisp dialect (I don't remember its name). However, given the flexibility of Lisp, it ...


13

How do you propose the head be reached in this reversed list? If not using mutable structures the reversed list would only be performant if you made the head linear time and tail constant. But now you've got the exact same structure as before except you're calling the head the tail and vice versa. the structure is the way it is because regardless of which ...


13

Well, the other answers cover what \() -> "something" means in Haskell: an unary function that takes () as argument. What is a function without arguments? – A value. Actually, it can occasionally be useful to think of variables as nullary functions that evaluate to their value. The let-syntax for a function without arguments (which doesn't actually exist)...


12

I use Haskell and Scala (and also doing some Scheme, Common Lisp, SML, OCaml, Erlang) all under Linux (Ubuntu). All of the above languages (compilers and interpreters) can be installed quite easily (there are packages that can be installed using apt-get or another package management system). Scala has a good integration with Eclipse and the Scala plugin(s) ...


12

Quote Quote returns data which you should not modify, and which may share structure between themselves. E.g. if you have a file which contains (define l1 '(1 2 3)) (define l2 '(4 2 3)) then the compiler is permitted to allocate l1 and l2 in a way that they share their common tail (cdr l1) and (cdr l2) and/or in the read-only memory. Modification of such ...


10

MacOS requires Mac hardware or you might get it to run on VirtualBox, but last time I tried that it didn't work. And since you don't want to replace your current configuration/setup problems with other problems, I suggest you either spend a lot of money or try linux. I've used Ubuntu for Haskell, Scala and Lisp development with Eclipse, Netbeans, IntelliJ ...


10

In that section of the book, filter, map, and enumerate-interval are presumed to return sequences, which are conceptually distinct from lists. You can implement sequences using streams, for example, though you can implement sequences using lists too. So, in this case, the accumulate with cons is to convert the sequence to a list.


10

Maybe an objective (if indirect) measure would be useful here. Consider the sizes of the specifications for the languages. Racket is basically an implementation of R6RS Scheme. The R6RS specification is 90 pages long, total. Of that, about 25 pages are devoted to the language proper, and about 30 more are devoted to its standard library. Along with that, ...


9

Frege says in "Funktion und Begriff" (1891): Wie nun Funktionen von Gegenständen grundverschieden sind, so sind auch Funktionen, deren Argumente Funktionen sind und sein müssen, grundverschieden von Funktionen, deren Argumente Gegenstände sind und nichts anderes sein können. Diese nenne ich Funktionen erster, jene Funktionen zweiter Stufe. In ...


9

I'm not so sure I believe these people. I've gone through SICP and the biggest blocker you'll run into is how call-with-current-continuation (call/cc) is implemented. While MIT-Scheme is officially endorsed, there are a few downsides to MIT-Scheme Old Unmaintained as far as I can tell Pretty mediocre environment/repl Not so great errors On the other hand ...


9

You're misinterpreting what () means in Haskell. It isn't the lack of a value, it is rather the only value of the Unit type (the type itself being referred to by an empty set of parentheses ()). Since lambdas can be constructed to use pattern matching, the lambda expression \() -> "s" is explicitly saying "create an anonymous function, expecting an input ...


8

If you want to learn Lisp today, I'd have a look at either racket, which is a fast scheme implementation (well, it actually departed a little from scheme, so it is its own dialect now) or clojure, which benefits from the JVM it runs on (so gazillions of libraries are available, plus you can make it interact with your own Java code). Even if you don't learn ...


8

Generally, programming language specifications are not very good tutorials. They are worded so as to be prescriptive rather than descriptive, although I think the best specifications identify discrete, separable requirements in simple, disjoint shall statements that are pretty easy to evaluate, and are further documented with a description and an example. ...


8

Further to ratchet freak's comment, look up discriminated union, or tagged union. You can make your data type a void *, but you also need to track what it really points to. That is, at some point you need to figure out if it's an integer or a double or another list. The tagged union itself might look something like this: #include <stdlib.h> #include ...


7

We have applied denotational semantics to language design itself, arguing that the design of languages, in particular, domain-specific languages, should start with the definition of the semantics. If you are interested in the details, you might want to take a look at Semantics-Driven DSL Design and Semantics First! Rethinking the Language Design Process.


6

CL type system is more expressive than the Haskell one, e.g., you can have a type (or (integer 1 10) (integer 20 30)) for a value 1,2,...9,10,20,21,...,30. However, Lisp compilers does not force their understanding of type safety down your throat, so you can ignore their "notes" - at your own risk. This means that you can write Haskell in Lisp (so to speak)...


6

Untyped Lambda Calculus is untyped, because it doesn't concern itself with types. Untyped Lambda Calculus is not a practical programming language, but merely a foundation for a practical programming language. Scheme is typed, because in the real world we have to store and manipulate real data, rather than mathematical symbols. That Scheme is based on the ...


6

Six joins doesn't sound like a lot to me, and I work with multi-tenant databases all day long. My advice is to join on your tenant ID at each step, and build your primary keys with tenant ID in them. That should get you 90% of the way there. If you still need more performance, look at the execution plans and determine if you need to reorder some joins or add ...


5

Typed Racket is very different from Haskell. Type systems in Lisp and Scheme, and indeed type systems in traditionally untyped language ecosystems in general, have a fundamental goal that other type systems do not - interoperating with existing untyped code. Typed Racket for example introduced whole new typing rules to accommodate various Racket idioms. ...


5

All of the Unix-like OSes have very good command line tooling. I've personally had good experiences with Ubuntu for both development and deployment, many of my friends also swear by MacOS. I've not seen an obvious reason to prefer one or the other, they are all IMO better than Windows for command line work. On the Clojure/Scala side specifically, you may ...


5

Common Lisp has a large standard library. Then again, so does Racket. The main difference is that Racket separates everything out into modules, so that programs that don't use all of the standard library don't have to see it. You just import the bits you want to use, and the rest is neatly hidden away.


Only top voted, non community-wiki answers of a minimum length are eligible