Tag Info

Accepted

Schemey - lexer

Overall, the code is quite clean and understandable. Though, I have never done anything like you are doing, but here are some notes about the code: the Token and <...
• 17.3k
Accepted

SICP 1.3 Sum of Squares of two largest numbers

In my opinion this is too much code for such a simple task. Assuming that you do not have a max function, you can define it in this way: ...
• 2,055
Accepted

Simplifying Macro-Generating Racket Macro

Starting at the top, you have a lot of unused imports. Fortunately, DrRacket can tell you which imports are unused, since it will highlight them in red when you hover your mouse over them. ...
• 3,172
Accepted

Pascal's triangle in mit-scheme

Keep your concerns separated One design principle that is vital to engineering good software is that of "separation of concerns". In other words, each function should be concerned with doing one, ...
• 895
Accepted

Proper use of tail recursion while forming a list

Your algorithm is okay, but the real issue with this code is that your code style is atrocious, bordering on unreadable. Your style exhibits four main problems: Scheme is not C, and parentheses are ...
• 3,172

Iterative "counting change" implementation in mit-scheme

In SICP the authors note: Count-change generates a tree-recursive process with redundancies similar to those in our first implementation of fib. (It will take quite a while for that 292 to be ...
• 41

Peter Norvigs' lis.py in c++17

Is std::list the best choice for the List datatype? There are a couple of places where using operator[] would make the code a little easier to read but std::list doesn't provide that. On the other ...
• 988

Calculate the sum of the square of two biggest numbers out of three

One of the ways of obtaining concision is by “astracting” a repeated operation to define a new function. For instance in this case you could use the square function ...
• 2,055
Accepted

Is this OR procedure correct?

or-l Is a Poor Name The OP procedure or-l is correct in that it yields correct results for its inputs. This ...
• 806
Accepted

Performant Text File Reading in Scheme

Thank you for this very nice investigation into timings. With all due respect, I don't view those figures as performant at all. More on that later. file->string1...
• 27.4k
Accepted

SICP - exercise 1.7 better end test for square root approximation

sqrt-iter You compute (improve guess x) twice - this is a waste. You return guess instead ...
• 1,405
Accepted

Church Numerals

Your function + is not correct. The definition of the sum of two Church numerals is the following: ...
• 2,055
Accepted

SICP exercise 1.28 - miller-rabin primality test

To ensure I understood the SICP exercise correctly, I wrote my own version of the Miller-Rabin algorithm. You can look at my code and compare against yours. With this in mind, here's my correctness-...
• 2,342
Accepted

SICP - exercise 1.12 - pascal's triangle

You should memoise the recursive call in order to make it faster. Since each value has a computational sibling (its value is derived from (one or two) parents which also each has another child), you ...
• 2,342
Accepted

Binary search tree insertion in Racket

As you suspected, you don't need append for this problem. The trick is to notice that if, for example, your goal is to create the list ...
• 146
Accepted

RPN calculator in Chicken Scheme

You've actually run into a big gotcha here. Scheme doesn't actually specify the order to evaluate operands. This can be a problem for code with side effects, especially if you aren't careful to ...
• 501
Accepted

Lex Scheme in Rust

You have several variations on this in your code: ...
• 30.2k
Accepted

Flattening a List containing Empty Lists

In general flatten is intended to flat a tree, not a list, that is to collect all the non-null leaves of the tree in the same order as a classical traversal of the ...
• 2,055
Accepted

SICP - exercise 1.11 - tree recursion

Before looking for efficiency, note that there is a logical error in the tail recursive version of your function: it does not terminate on negative values (while the first function does terminate). ...
• 2,055

Purely functional Sieve of Eratosthenes

Here's a small refinement on the technique. Wherin instead of looking for odd multiples and removing them, you keep an extra reference in the incomplete sieve and look those specific multiples of the ...
• 501

Merge sort in Scheme

Four years, 1400 views, and two dozen upvotes before a review on a site dedicated to code reviews points toward unreviewability as a prominent feature of the code. What hinders reviewability is, I ...
• 2,663
Accepted

Function that tests whether all items in a list are the same

First, a note about testing: inside singleton-list? you check if the argument is a pair, while it is called by all-same? always ...
• 2,055

Remove the last occurrence of an item in a list

Always tell the truth ;) By the way, you'll have noticed that all procedures are implemented using tail recursion. Now that's not correct, is it? The only tail recursive functions in the code you ...
• 1,581
Accepted

Remove the last occurrence of an item in a list

Youre solution is very inefficient. The classical, efficient solution is simply to reverse the list, remove the first occurrence of the item, than reverse again the list. So, using only your ...
• 2,055

Pascal's triangle in mit-scheme

The sub-definition of pascal-item is what is being asked for in the 1.12 exercise. However it's entirely unsuited for calculating the entire triangle of X rows. ...
• 501

Iterative "counting change" implementation in mit-scheme

If you add a running sum to the formal parameters of count-iter, you'll have a truly iterative piece of code. As-is, every time through ...
• 501

Sudoku solver in Racket

This looks like a fairly reasonable brute force method. From what I've gathered though, the for loop will try for all combination rather than just the first valid ...
• 501