Barry Margolin <barmar@bbnplanet.com> wrote:
+---------------
| Topharrier <topharrier@aol.com> wrote:
| >(define rm '("room 1"
| > (("ball") ("string"))
| > (("east" tr) ("south" tr))))
| >
| >I need to be able to delete the objects from the second of the list
| >like ("ball")
| >
| >anyone knows how can I acomplish this?
|
| (define (delete item list predicate) ...)
|
| (define (delete-from-room object room)
| (set-car! (cdr room)
| (delete object (cdr room)
| (lambda (object entry) (string= object (car entry))))))
|
| (delete-from-room "ball" rm)
+---------------
Well, in Scheme it's "string=?", not "string=", and even then:
> (delete-from-room "ball" rm)
error: "string=?": expects type <string> as 2nd arg; given ("ball")
>
Actually, I don't understand why the original data structure has the
objects in the "room" in individual lists, unless maybe it's to allow
multiple attributes on the objects or something, e.g.
> (define rm '("room 1"
(("ball" "red" "small") ("string" "long" "weak"))
(("east" tr) ("south" tr))))
In which case, you'd need a much more general (read: complex) matching
function for "delete-from-room", so it could accept requests like this:
(delete-from-room '("ball" (or "red" "green")) rm)
Anyway, "Topharrier", Barry's code (even if it doesn't quite work)
is a *much* bigger "hint" than my verbiage... Good luck.
-Rob
-----
Rob Warnock, 8L-846 rpw3@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. FAX: 650-933-0511
Mountain View, CA 94043 PP-ASEL-IA