Search found 6 matches

by zcohen
Thu Aug 30, 2012 3:51 am
Forum: Homework
Topic: count occurences in a list
Replies: 1
Views: 7443

count occurences in a list

Hi everybody, I apologize for the bad English.. I have a task to write a function called "make-bag" that counts occurences of every value in a list and returns a list of dotted pairs like this: '((value1 . num-occurences1) (value2 . num-occurences2) ...) For example: > (make-bag '(d c a b ...
by zcohen
Sun Jun 17, 2012 6:52 am
Forum: Homework
Topic: Use assoc with argument of type string
Replies: 2
Views: 7854

Re: Use assoc with argument of type string

ou were close with intern; you just had the case wrong. Try this: > (assoc (intern "A") base-list) (A . 0) Note that here the name-as-string is capitalized. Alternately, you could use find-symbol to look for an existing symbol by name: > (assoc (find-symbol "A") base-list) (A . 0...
by zcohen
Sun Jun 17, 2012 5:00 am
Forum: Homework
Topic: Use assoc with argument of type string
Replies: 2
Views: 7854

Use assoc with argument of type string

Hi everybody, I have this association-list: (defvar base-list (list (cons 'a 0) (cons 2 'c))) I have to call assoc when my argument is of type string. So for the pair (A . 0) I have to convert "a" to a symbol, and for the pair (2 . C) I have to convert "2" to a symbol. How can I ...
by zcohen
Tue Jun 12, 2012 9:18 am
Forum: Homework
Topic: Function to "push" a list to the right or left
Replies: 1
Views: 9171

Function to "push" a list to the right or left

Hi everybody, I have to write a function that (push-left (L)) "pushes" a list to thr right or to the left. For example: (push-left '(1 2 3 4)) will give (2 3 4 1) (push-right'(1 2 3 4)) will give (4 1 2 3) The lecturer said we can't use functions 'last' or 'butlast'. I tried to solve it wi...
by zcohen
Wed Jun 06, 2012 5:17 am
Forum: Homework
Topic: Why the function doesn't work?
Replies: 2
Views: 7758

Re: Why the function doesn't work?

Ramarren wrote:It seems to work. Are you sure you defined the function as included, and not some other version?
It actually works. For some reason, It worked only when I copied the function to a new .lisp file.
Thanks anyway
by zcohen
Wed Jun 06, 2012 12:56 am
Forum: Homework
Topic: Why the function doesn't work?
Replies: 2
Views: 7758

Why the function doesn't work?

Hi everybody, I have this function that gets 2 parameters - one of them is optional. It does this: if x is an empty list or not a list return the optional parameter. else - return a list that contains length(x) and list of last value of x and the optional parameter. This is the function: (defun last...