Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
5 votes
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 <...
alecxe's user avatar
  • 17.3k
4 votes
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: ...
Renzo's user avatar
  • 2,055
4 votes
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. ...
Alexis King's user avatar
  • 3,172
4 votes
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, ...
Nathan Davis's user avatar
4 votes
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 ...
Alexis King's user avatar
  • 3,172
4 votes

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 ...
Richard's user avatar
  • 41
4 votes

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 ...
bipll's user avatar
  • 988
4 votes

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 ...
Renzo's user avatar
  • 2,055
4 votes
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 ...
ad absurdum's user avatar
4 votes
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...
J_H's user avatar
  • 27.4k
3 votes
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 ...
sds's user avatar
  • 1,405
3 votes
Accepted

Church Numerals

Your function + is not correct. The definition of the sum of two Church numerals is the following: ...
Renzo's user avatar
  • 2,055
3 votes
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-...
C. K. Young's user avatar
  • 2,342
3 votes
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 ...
C. K. Young's user avatar
  • 2,342
3 votes
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 ...
assefamaru's user avatar
3 votes
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 ...
WorBlux's user avatar
  • 501
3 votes
Accepted

Lex Scheme in Rust

You have several variations on this in your code: ...
Winston Ewert's user avatar
3 votes
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 ...
Renzo's user avatar
  • 2,055
2 votes
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). ...
Renzo's user avatar
  • 2,055
2 votes

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 ...
WorBlux's user avatar
  • 501
2 votes

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 ...
ben rudgers's user avatar
  • 2,663
2 votes
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 ...
Renzo's user avatar
  • 2,055
2 votes

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 ...
Daniel Jour's user avatar
  • 1,581
2 votes
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 ...
Renzo's user avatar
  • 2,055
2 votes

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. ...
WorBlux's user avatar
  • 501
2 votes

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 ...
WorBlux's user avatar
  • 501
2 votes

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 ...
WorBlux's user avatar
  • 501
2 votes

Proper use of tail recursion while forming a list

First, a few useful notation conventions: In Lisp languages - is commonly used instead of _ to form composite nouns (so ...
Renzo's user avatar
  • 2,055
2 votes

Find common factor of numbers in a list

Scheme has a built-in function called gcd, which computes the greatest common divisor. You don't need to write your own version. ...
C. K. Young's user avatar
  • 2,342

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