Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 30th, 2012, 04:23 PM
TaroOderSo TaroOderSo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 1 TaroOderSo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 4 sec
Reputation Power: 0
Scheme lookup-function

Hello, everyone. I have a problem with scheme or, more precisely, with writing a script that contains a lookup-function that searches for a key in a pre-defined list and prints the value of the key (pair).

My problem is, that i have to do it with the define-struct-construction.

My script (until now):
PHP Code:
(define-struct pair (key value))

(
define table (list
 (
make-pair 'o 3)
 (make-pair '
r 5)
 (
make-pair 'x 9)))

(define (lookup key lst)           
  (let ((pair (assoc key lst)))
      (if pair                     
          (cadr pair)          
      (error key " not in list."))))

(lookup '
o table


And my error message:

PHP Code:
 assocnon-pair found in list: (make-pair 'o 3) in 
(list (make-pair '
o 3) (make-pair 'r 5) (make-pair 'x 9)) 


The program should find the pairs but instead tells me that there are not even pairs ("non-pairs"); I guess I do not understand how to use define-struct pair correctly. I searched the forum and like 5 hours or so on google and a LOT of other websites. I appreciate your help and hope you understand my problem. Sorry for bad English - Non-native speaker

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Scheme lookup-function

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap