All Questions
28 questions
0
votes
2
answers
240
views
How does scramble function works? (Chapter 1 of The Seasoned Schemer)
According to the book, this is what the function definition is,
The function scramble takes a non-empty tuple in which no argument is greater than its own index and returns a tuple of same length. ...
2
votes
4
answers
588
views
Reversing list vs non tail recursion when traversing lists
I wonder how do you, experienced lispers / functional programmers usually make decision what to use. Compare:
(define (my-map1 f lst)
(reverse
(let loop ([lst lst] [acc '()])
(if (empty? lst)...
0
votes
1
answer
109
views
Generating permutations in Lisp withous map functions
I want to generate in Lisp the list of all permutations of a set. This is what I tried:
(defun ins(e n l)
(cond
((equal n 1) (cons e l))
(T (cons (car l) (ins e (1- n) (cdr l))))
...
0
votes
0
answers
26
views
Even maximums in Lisp [duplicate]
I am trying to find the even maximums from a list in Lisp.
(defun m(L)
(cond
((numberp L) L)
((atom L) most-negative-fixnum)
(T (apply #'max (mapcar #'m L)))
)
)
This &...
3
votes
4
answers
138
views
How to return false if the number is not found in the list
So, I am trying to do this hw problem: write a function that takes two arguments, a list and a number, and the function returns the index of the leftmost occurrence of the number in the list. For ...
4
votes
5
answers
421
views
Understanding Peter Norvig's permutation solution in PAIP
Peter Norvig's PAIP book contains this code as a solution to the permutation problem (some sections are removed for brevity)
(defun permutations (bag)
;; If the input is nil, there is only one ...
1
vote
3
answers
803
views
Recursive processing of list elements in LISP
Here is a task: a list is given, some of the elements are also lists. It's nescessary to replace the nested lists with the sum of the numbers in them, if all of them are even, using recursion. For ...
0
votes
2
answers
457
views
Scheme: Mapping a list as argument to a function
If I have a function that takes 3 arguments, and returns a list:
(some-function 1 2 3) --> '(3 2 1)
and I have a list of lists like this:
( (1 2 3) (2 1 3) (3 2 1) )
How can I map "some-function" ...
0
votes
1
answer
355
views
Function with SUCC
I have some problems with this exercise
COTO(0,y)=y
COTO(x+1,y)=SUCC(SUCC(COTO(x, SUCC(y)))
COTO (1,3); COTO (2,2); COTO (3,44) - ?
I know that SUCC(2) = 3, for example, but I still don't have any ...
1
vote
1
answer
848
views
Recursively find and return a pattern in a list using only basic lisp
The function I need to write takes two arguments: a pattern (p) and a list (L). I want to find the part of the list that contains the pattern as well as everything after the pattern. If the pattern is ...
-2
votes
1
answer
337
views
Why does this lisp function return nil?
I am trying to build a lisp function that will car and cdr through a list while comparing the values in that list to a max value. If a value in the list is larger than the max value then that value is ...
-1
votes
2
answers
264
views
Need help finding second largest number in a list. Racket [closed]
I've been struggling with this question for a lot now. Could someone please explain the logic behind the program by using the simplest way possible possibly recursion?
Thank you.
0
votes
3
answers
910
views
Recursively handle nested lists in scala
I'm teaching myself scala and trying to fatten my FP skills.
One of my references, Essentials of Programming Languages (available here), has a handy list of easy recursive functions. On page page 27/...
0
votes
1
answer
194
views
Recur not at tail position
How can I use something similiar to recurnot at tail position?
Take a look at my code:
(defn -main [& args]
(println "Hi! Type a file name...")
(defn readFile[])
(let [fileName(read-...
-1
votes
3
answers
83
views
Replacing every occurrence of an element in a list, only when it follows a specified element
I am trying to write a function replaceAfter(A X Y L) that replaces every occurrence of X with Y in L, only when X comes after A.
Example:
replaceAfter d m t '(f d s d m p m h d m u m) -> '(f d s ...