(define (lcs lst1 lst2)
(define (except-last-pair list)
(if (pair? (cdr list))
(cons (car list) (except-last-pair (cdr list)))
'()))
(define (car-last-pair list)
(if (pair? (cdr list))
(car-last-pair (cdr list))
(car list)))
(if (or (null? lst1) (null? lst2)) null
(if (= (car-last-pair lst1) (car-last-pair l...
I've begun working through Structure and Interpretation of Computer Programs. Dutifully, I've installed mit-scheme. What I need now is an editor/IDE for the Mac that can handle the indentation and balance parentheses (or advice on how to best to configure the packaged tools).
Any suggestions?
TIA
...
Hello everybody:
I tried to implement a "pairing heap" with all the regular operations (merge, delete-min etc.), then I've been requested to write a function that would sort a list using my newly constructed heap implementation. Unfortunately it seems that someting goes wrong...
Here's the relevant code:
(define (heap-merge h1 h2)
(...
Anyone know of a good / small scheme interpreter in C++? Perferably something < 2000 LOC, with a simple garbage collectro (either compacting or mark & sweep), no need to support all of R5RS, just basics of if/lambda/set!/cons/car/cdr and some basic operations.
Thanks!
...
Let me establish that this is part of a class assignment, so I'm definitely not looking for a complete code answer. Essentially we need to write a converter in Scheme that takes a list representing a mathematical equation in infix format and then output a list with the equation in postfix format.
We've been provided with the algorithm t...
My problem isn't with the built-in eval procedure but how to create a simplistic version of it. Just for starters I would like to be able to take this in '(+ 1 2) and have it evaluate the expression + where the quote usually takes off the evaluation.
I have been thinking about this and found a couple things that might be useful:
Unquote...
Hi,
I am trying to extract the field 'name' or 'named-expr' from the following object:
(bind 'x (num 5)) ;; note that this is not a list, but a type Binding
With the Binding definition:
(define-type Binding
(bind (name symbol?) (named-expr WAE?)))
I have tried, but received the error "reference to an identifier before its definiti...
I have a Scheme macro and a long list, and I'd like to map the macro across the list, just as if it were a function. How can I do that using R5RS?
The macro accepts several arguments:
(mac a b c d)
The list has
(define my-list ((a1 b1 c1 d1)
(a2 b2 c2 d2)
...
(an bn cn dn)))
And ...
I have to determine if an undirected graph contains a cycle or not. I shoudn't use set! instructions.
I tried using DFS, but I don't know how to mark the visited nodes.
...
It's been a few months since I've touched Scheme and decided to implement a command line income partitioner using Scheme.
My initial implementation used plain recursion over the continuation, but I figured a continuation would be more appropriate to this type of program. I would appreciate it if anyone (more skilled with Scheme than I) ...
(define (member atom list)
(cond
((null? list) '())
(= atom (car list) "True")
(else
(member atom(cdr list)))
)
)
(member '5 '(1 2 3 4 5))
Always it gives true even though that atom isn't a member in the list. Could you plz help me to clarify this question as soon as possible.
...
Anything like flatten, count-atoms, etc. over nested lists would do fine.
BTW, I'm not interested in a CPS transformation or "pairs-trees".
...
Hi,
In Scheme, procedures like +, -, *, / works on different types of numbers, but we don't much see any other generic procedures.
For example, length works only on list so that vector-length and string-length are needed.
I guess it comes from the fact that the language doesn't really offer any mechanism for defining generic procedure...
I'm trying to grasp the semantics of call/cc in Scheme, and the Wikipedia page on continuations shows the yin-yang puzzle as an example:
(let* ((yin
((lambda (cc) (display #\@) cc) (call-with-current-continuation (lambda (c) c))))
(yang
((lambda (cc) (display #\*) cc) (call-with-current-continuation (lambda (c) ...
Hi guys, any tail-recursive version for the below mentioned pseudocode ? Thanks !
(define (min list)
(cond
((null? list) '())
((null? (cdr list)) (car list))
(#t (let ((a (car list))
(b (min (cdr list))))
(if (< b a) b a)))))
...
I need some help understanding some of the points from Paul Graham's article http://www.paulgraham.com/diff.html
A new concept of variables. In Lisp, all variables are effectively pointers. Values are what have types, not variables, and assigning or binding variables means copying pointers, not what they point to.
A symbol type. Symbol...
Sometimes in Scheme, I have functions that take arguments like this
add 3 4
What do you call this kind of "list" where it's elements are like a1 a2 a3 ? I don't think you can call it a list because lists are contained in parenthesis and elements are comma-seperated.
...
Hello:
I'm using drscheme from:
http://www.archlinux.org/packages/extra/x86_64/drscheme/
I'm trying to work with the sample code in my textbook, but I keep getting getting "unbound identifier" errors. Is it because the scheme interpreter is not configured correctly? or is the code just plain wrong?
Here are a few examples:
Input:
#l...
Hi Im facing a problem with the car and cdr functions
for example:
first I defined a list called it x
(define x (a (bc) d ( (ef) g ) ))
so x now is equal to (a (bc) d ( (ef) g ) )
now for example I need to get the g from this list using only car and cdr
(!! noshortcuts as caddr cddr !!) the correct answer is:
(car(cdr(car(cdr(cdr...
;; definition of the structure "book"
;; author: string - the author of the book
;; title: string - the title of the book
;; genre: symbol - the genre
(define-struct book (author title genre))
(define lotr1 (make-book "John R. R. Tolkien"
"The Fellowship of the Ring"
'Fantasy))
(define ...