8
votes
Occurrences (frequency count) - exercise 3 ch. 3 in "ansi common lisp"
Use primitive functions and operators as much as possible
You are defining remove-dups, and in this function you use the primitive ...
7
votes
Count frequencies of symbols in a list
This is the typical situation where a hash table that maps elements to their frequency count is particularly well suited.
...
6
votes
Returning the prime factors of a number
There are several problems with your code.
Style
is-prime is C/Java style. Lispers use primep or ...
6
votes
FizzBuzz in Common Lisp
1. Divisible function
It is perfectly fine to define a function like divisible to improve the reading of a program. In general, ...
6
votes
Accepted
lisp-koans Greed implementation
Don't take all remarks as absolute. Some are just how I would do things. There are many ways to structure a program.
It's a great way to learn Lisp programming!
Good:
documented constant values with ...
6
votes
Find minimum value in a BST: using boolean operators, and using conditionals
The aspect of the code that may cause difficulty to those new to Lisp appears to be the fact that in Common Lisp, nil has two meanings. It's the value of an empty ...
6
votes
Accepted
Find minimum value in a BST: using boolean operators, and using conditionals
You are asking:
which version would you favour and why?
Instead of answering directly to your question, I will try to show why that formulation is not, at least in my opinion, “a relic of former ...
6
votes
Simple JSON parser in lisp
specification
Please mention the URL of a JSON spec. near the top of this codebase.
Extra points for mentioning the URL of some corpus of
known-good and known-bad inputs you have tested against.
EOF ...
6
votes
Simple JSON parser in lisp
(defun mk-scanner (s) (list :stream s :cursor 0))
Using a property list for your scanner type is pretty unusual. Normally in Common Lisp you'd use a structure or ...
5
votes
merge function for mergesort - recursion vs. iteration
There are some cases to be considered. Though we can write it slightly different:
...
5
votes
pos+ (value added to position) - ex 3.5 in “ANSI Common Lisp” (p57)
For loop you can see the excellent book by P. Seibel “Practical Common Lisp”, available on-line, in particular chapter 7 and chapter 22.
Let’s start from the last ...
5
votes
Accepted
Lispy code? Sum multiples of 3 or 5 up to 1000
Conditions
In general something like "if a then true else false" can be simplified as "a". So your first function could be simplified as:
...
5
votes
Accepted
count pairs of matching integers in a collection in Common Lisp
Stylistic consideration: a global variable is usually written with double "*" (earmuffs), so the global variable integers should be written as ...
4
votes
Accepted
Reading lines of integers into a list of lists
A simple possibility could be to enclose each row between parentheses and use read-from-string (assuming that the file does not contain incorrect data):
...
4
votes
Accepted
Implementing a tree parsing function
A few considerations about the style of the code.
Generalized booleans
In Common Lisp the only value “false” is NIL, every other value is considered “true”. So, ...
4
votes
Accepted
A simple Tic Tac Toe game
Here are a few considerations.
DEFPARAMETER vs. DEFVAR
The first three definitions should be given with defparameter instead of ...
4
votes
pos+ (value added to position) - ex 3.5 in “ANSI Common Lisp” (p57)
General style remarks
lst is more of a Scheme idiom, in Common Lisp you don't eat vowels but write directly list if your ...
4
votes
Accepted
BST traverse as higher order function
Is this higher order function any use at all without relying on a side-effect?
The answer to this question is obviously no, since the function returns always nil.
...
4
votes
Accepted
Lispy code? Prime factors of a number
Your code is perfectly fine, except for a few nitpicks.
Use push instead of (setf x (conx y x)) for readability.
Use ...
4
votes
Accepted
Deque class in Common Lisp
little review based on this style guide: https://lisp-lang.org/style-guide/, itself much based on Google's.
the slots order should be accessor, initarg, initform, type.
use the :type slot. They are ...
4
votes
Accepted
Count complete trips to the basement and back to ground floor
A few points.
if with only the “then” case is usually written with when, which is in general more handy since it allows several ...
4
votes
Accepted
Lexically-scoped Lisp interpreter
Interesting project.
Being "similar" to a big system like Common Lisp
introduces a pretty giant documentation burden.
Consider starting with R7RS-small,
and then describing the deltas.
...
4
votes
Advent of Code 2015 "Not Quite Lisp", in Common Lisp
I'd write this in Common Lisp as something like
...
3
votes
Accepted
Calculating the cube root
There is not much to say about this code, it is fine.
You can get rid of incf and setf; the varying ...
3
votes
Accepted
Nested loop in lisp to process a 2d array - what's good style (with and/or without loop macro)?
A few comments about your code:
Why introduce a new variable n copy of another variable? If you want to be more concise you could use ...
3
votes
Accepted
Extracting XML data from a node in Common Lisp (Closure XML DOM)
you can use REMOVE instead of the LOOP
you can replace the CONDs and IFs and ERRORs with ASSERT
replace CAR with FIRST
The specific functions make the intent of the code a bit more clear.
Untested:
<...
3
votes
Accepted
3
votes
Accepted
Scoring poker hands
Some remarks:
&aux variables can reduce the indentation level.
Here we can also get rid of the with & ...
3
votes
Accepted
Split a list into two parts with a given length
Let’s use a completely different approach: first try to solve the problem using predefined (complex) functions, then implement those functions with the primitive ones (recursion, car, cdr, etc.)
So, ...
3
votes
Insertion sort in Common Lisp
You were trying to implement the algorithm as it is described for collections with certain properties, which, as noted by sds led you to create a very inefficient implementation, since the property ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
common-lisp × 126lisp × 58
beginner × 18
strings × 8
programming-challenge × 7
functional-programming × 6
performance × 5
recursion × 5
macros × 5
sorting × 4
primes × 4
algorithm × 3
tree × 3
combinatorics × 3
fizzbuzz × 3
parsing × 2
unit-testing × 2
json × 2
file-system × 2
integer × 2
converting × 2
mergesort × 2
compression × 2
quick-sort × 2
factors × 2