Search found 45 matches
- Wed Jan 16, 2013 11:43 am
- Forum: Scheme
- Topic: Final recursion.
- Replies: 1
- Views: 10519
Re: Final recursion.
Firstly, you will need to quote the identifiers in your 'case' statement. I believe that your individual parsers (trec-if, trec-cond, trec-begin, ...) should be implemented something like the following: (define (trec-if fun expr term) (let ((consequent (cadr expr)) (alternative (caddr expr)) ) (if (...
- Thu Aug 30, 2012 11:18 am
- Forum: Homework
- Topic: count occurences in a list
- Replies: 1
- Views: 7570
Re: count occurences in a list
Start with an empty dictionary (an alist ), and then traverse your input (using recursion); if you encounter an item that is not in your dictionary, add it with a count of "1". If the item you encounter is already in the dictionary, increment its count. When you reach the end of your input...
- Fri Aug 24, 2012 7:53 am
- Forum: Common Lisp
- Topic: New to lisp and file IO
- Replies: 2
- Views: 5998
Re: New to lisp and file IO
So i have 1 - (defparameter *s* (open animals)) Then i get kinda lost. 2 - (read *s*) ??? : : so far my file animals has "((Emu)(Dog Beaver))" The effect of reading an expression from a file is basically equivalent to what you would obtain by quoting the expression. (defparameter *s* '((E...
- Tue Aug 21, 2012 4:26 am
- Forum: Homework
- Topic: first, rest, second, last
- Replies: 3
- Views: 10705
Re: first, rest, second, last
Why does first return NIL and rest return (NIL)? One can always be certain that there is only one first item in the list. Without knowing the length of the list, it is not possible to know how many items follow the first, so 'rest' returns them all as a list. Consider what (rest '(NIL NIL NIL)) eva...
- Tue Jul 24, 2012 7:50 am
- Forum: Homework
- Topic: Tree and linked list in lisp
- Replies: 2
- Views: 8267
Re: Tree and linked list in lisp
If you don't mind reading a bit of C code then GNU's libavl documentation provides some of the most comprehensive coverage of binary trees I know of. It is written in a sort of "Donald Knuth documented code" style.
Re: cons
Even if unquoted empty lists were recognized, the following part of your expression is not a pair:
Code: Select all
(cons (cons 12 ()) )
- Mon Jul 23, 2012 12:36 pm
- Forum: The Lounge
- Topic: Another homily from Paul Graham
- Replies: 0
- Views: 8311
Another homily from Paul Graham
http://www.paulgraham.com/icad.html
While for this forum it is largely a matter of preaching to the choir, the sermon is nonetheless enjoyable.
While for this forum it is largely a matter of preaching to the choir, the sermon is nonetheless enjoyable.
Re: Macros
(define (remove-duplicates lis) (cond ((null? lis) '() ) ((member (car lis) (cdr lis)) (remove-duplicates (cdr lis)) ) (else (cons (car lis) (remove-duplicates (cdr lis))) ))) (define-syntax quote-unique (syntax-rules () ((_ args ...) (remove-duplicates (quote (args ...))) ))) Perhaps?
- Thu Apr 19, 2012 3:58 am
- Forum: Common Lisp
- Topic: this queue program is not running showing error
- Replies: 4
- Views: 15245
Re: this queue program is not running showing error
Which dialect of Scheme are you running? (I don't know of any that use 'defun'.)
Also, you need to define all of your procedures push, pop, peek, show, and fb somewhere (so that they evaluate properly during invocation).
Also, you need to define all of your procedures push, pop, peek, show, and fb somewhere (so that they evaluate properly during invocation).
- Thu Mar 22, 2012 5:17 pm
- Forum: Scheme
- Topic: List Struture Equality
- Replies: 10
- Views: 32275
Re: List Struture Equality
The following assumes that for (sub)lists to be considered similar to each other, they must have the same number of elements. (define (similar-struct? obj1 obj2) (cond ((and (atom? obj1) (atom? obj2)) #t ) ((atom? obj1) #f ) ((atom? obj2) #f) (else (and (similar-struct? (car obj1) (car obj2)) (simil...